简单的htaccess重写/重定向到搜索页面

编程入门 行业动态 更新时间:2024-10-28 20:30:56
本文介绍了简单的htaccess重写/重定向到搜索页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我发送一个GET请求到一个名为的search.php网页搜索表单。我有重写建立在改写某些事情,比如/搜索我的htaccess文件的规则,以各自的网页。我只是想采取的search.php?Q =查询并将其重写/搜索/查询。

下面是我。

重写规则的search.php?Q =(。*)/搜索/ $ 1 重写规则搜索/(.*)的search.php?Q = $ 1 [NC]

我是什么做错了吗?!

下面是完整的文件

的ErrorDocument 404 /index.php?p=404 选项​​+的FollowSymLinks RewriteEngine叙述上 的RewriteCond%{} REQUEST_FILENAME!-f 重写规则^图像/.* \ JPG $ /images/default.jpg [L] 的RewriteCond%{HTTP_REFERER}!^ $ 的RewriteCond%{HTTP_REFERER} ^ HTTP://(WWW \)wghandcrafted /.*$ [NC] 重写规则\(GIF | JPG | JPEG | PSD | JS |瑞士法郎| FLV | PNG)。$ /料/ [R = 302] 重写规则^(产品|博客|饲料|搜索|结帐|结帐)$ $ 1.PHP [NC] 重写规则的产品/猫/(.*)$ products.php类型=猫和放大器;猫= $ 1 [NC] 重写规则的产品/(.*)$ products.php类型=单&放大器;产品= $ 1 [NC] 重写规则博客/(.*)blog.php的&放大器;后= $ 1 [NC] 重写规则饲料/(.*)feed.phptype = $ 1 [NC] 重写规则搜索\的.php?Q =(。*)$ /搜索/ $ 1 [R = 301,L] 重写规则搜索/(.*)$的search.php?Q = $ 1 [NC]

解决方案

请在第一线执行重定向,第二进行重写

重写规则搜索\的.php?Q =(。*)$ /搜索/ $ 1 [R = 301,L] 重写规则搜索/(.*)$的search.php?Q = $ 1 [NC]

和移动

的RewriteCond%{} REQUEST_FILENAME!-f 重写规则^图像/.* \ JPG $ /images/default.jpg [L]

要的组规则的结尾。

否则,的RewriteCond%{} REQUEST_FILENAME!-f 规则别的之前制定的,这意味着只请求对不存在的文件将通过下面的规则来处理该行。由于有一个的search.php 文件,该prevents,从统治日益被达成。

I have a search form that sends a GET request to a page called search.php. I have rewrite rules set up in my htaccess file that rewrite certain things, like /search, to their respective pages. I simply want to take the search.php?q=query and rewrite it to /search/query.

Here is what I have.

RewriteRule search.php?q=(.*) /search/$1 RewriteRule search/(.*) search.php?q=$1 [nc]

What am I doing wrong?!

Here is the complete file

ErrorDocument 404 /index.php?p=404 Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^images/.*\.jpg$ /images/default.jpg [L] RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^(www\.)?wghandcrafted/.*$ [NC] RewriteRule \.(gif|jpg|jpeg|psd|js|swf|flv|png)$ /feed/ [R=302] RewriteRule ^(products|blog|feed|search|checkout|checkout)$ $1.php [nc] RewriteRule products/cat/(.*)$ products.php?type=cat&cat=$1 [nc] RewriteRule products/(.*)$ products.php?type=single&product=$1 [nc] RewriteRule blog/(.*) blog.php&post=$1 [nc] RewriteRule feed/(.*) feed.phptype=$1 [nc] RewriteRule search\.php?q=(.*)$ /search/$1 [R=301,L] RewriteRule search/(.*)$ search.php?q=$1 [NC]

解决方案

Make the first line perform a Redirect and the second perform a Rewrite

RewriteRule search\.php?q=(.*)$ /search/$1 [R=301,L] RewriteRule search/(.*)$ search.php?q=$1 [NC]

and move

RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^images/.*\.jpg$ /images/default.jpg [L]

to the end of the set of rules.

Otherwise, the RewriteCond %{REQUEST_FILENAME} !-f rule is enacted before anything else, meaning that only requests for non-existant files will be handled by any rules below that line. As there is a search.php file, this prevents that rule from ever being reached.

更多推荐

简单的htaccess重写/重定向到搜索页面

本文发布于:2023-11-01 07:22:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1548651.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   重定向   页面   简单   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!