.htaccess mod_重写问题-射中自己的脚?

.htaccess mod_重写问题-射中自己的脚?,.htaccess,mod-rewrite,url-rewriting,friendly-url,.htaccess,Mod Rewrite,Url Rewriting,Friendly Url,我有一个名为category.php5的页面,它使用$_GET[“category”]从数据库中获取正确的内容。我想把它装饰一下,看起来是这样的: Sinaessesia.co.uk/category/牛皮癣 这相当于: Sinaessesia.co.uk/category.php5?category=银屑病 我以前已经成功地完成了这种重写,但由于我现在无法让它工作,我担心我可能有一些规则,不知怎么搞砸了我。这是我的整个.htaccess文件-最后几行应该进行上述重写: RewriteEngin

我有一个名为category.php5的页面,它使用$_GET[“category”]从数据库中获取正确的内容。我想把它装饰一下,看起来是这样的:

Sinaessesia.co.uk/category/牛皮癣

这相当于:

Sinaessesia.co.uk/category.php5?category=银屑病

我以前已经成功地完成了这种重写,但由于我现在无法让它工作,我担心我可能有一些规则,不知怎么搞砸了我。这是我的整个.htaccess文件-最后几行应该进行上述重写:

RewriteEngine On

#remember to change this to aromaclear
RewriteCond %{HTTP_HOST} !^sinaesthesia\.co.uk$ [NC]
RewriteRule ^(.*)$ http://sinaesthesia.co.uk/$1 [R=301,L]

#Translate default page to root
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php5|html)\ HTTP
RewriteRule ^(.*)index\.(php5|html)$ /$1 [R=301,L]

#translate any .html ending into .php5
RewriteRule ^(.*)\.html$ /$1\.php5

#change / for ?
RewriteRule ^(.*)\.html/(.*)$ /$1\.html?$2

#strip .html from search res page
RewriteRule ^(.*)search/(.*)$ /$1search_results\.html/search=$2

#translate product details link from search res page
RewriteRule ^products/(.*)/(.*)/(.*)$ /product_details.php5?category=$1&title=$2&id=$3 [L]

#Translate products/psorisis/chamomile-skin-cream-P[x] to productview.php5?id=1
RewriteRule ^products/.*-P([0-9]+) /productview.php5?id=$1 [L]

#Translate /category/psoriasis to /category.php5?category=$1
RewriteRule ^category/(.*) /category.php5?category=$1 [L]

当我手动输入category.php5/category=psoriasis时,效果非常好。当我进入category.php5/category/psoriasis时,它没有。我担心我的行会将html/更改为html?是一个错误,但是当我把那条线取出来时,它仍然不起作用。其他一切都按预期进行

一般策略是,通过注释所有内容来删除文件,然后逐个重新启用文件,直到找到导致文件崩溃的规则

请记住,浏览器有时会缓存重定向,因此启动新的浏览器实例是一个好主意。一个有用的服务是提供一个未缓存的结果

总的来说,看看你的重定向集,这对我来说似乎有点复杂,因为你使用的是链式/筛式系统。相反,我建议从可以明确识别的URL开始,例如从

RewriteRule ^category/(.*) /category.php5?category=$1 [L]
如果您最终需要的话,请在最后留下相当混乱的.html=>.php转换内容。我已经做了很多网站使用重定向,从来没有需要像这样的通用转换,所以他们应该是可以避免的


还要记住,.*意味着匹配任何或任何内容,因此您可能希望使用。+来代替。

作为一般策略,通过注释所有内容来删除文件,然后逐个重新启用,直到找到导致其崩溃的规则

请记住,浏览器有时会缓存重定向,因此启动新的浏览器实例是一个好主意。一个有用的服务是提供一个未缓存的结果

总的来说,看看你的重定向集,这对我来说似乎有点复杂,因为你使用的是链式/筛式系统。相反,我建议从可以明确识别的URL开始,例如从

RewriteRule ^category/(.*) /category.php5?category=$1 [L]
如果您最终需要的话,请在最后留下相当混乱的.html=>.php转换内容。我已经做了很多网站使用重定向,从来没有需要像这样的通用转换,所以他们应该是可以避免的


还请记住,.*表示匹配任何或任何内容,因此您可能希望使用“+”。

啊:因为我有一个名为category.php5的文档,并且我正在尝试使用category/psoriasis,服务器尝试将其作为category.php5/psoriasis解决,但失败了。现在修好了

Ah:因为我有一个名为category.php5的文档,并且我正在尝试使用category/psoriasis,所以服务器尝试将其解析为category.php5/psoriasis,但失败了。现在修好了

这些规则都不适用于该URL的请求吗?据我所知不适用-我得到的是直接的404状态。这些规则都不适用于该URL的请求吗?据我所知不适用-我得到的是直接的404状态。谢谢,这里有很好的建议。我会去做的,然后再给你回复-特别是,+是一个非常好的主意。好的,我试着将文件剥离为#Translate/category/psoriasis to/category.php5?category=psoriasis RewriteRule^category/(.+)$/category.php5?category=$1[L]并尝试,以防万一#将/category/psoriasis翻译为/category.php5?category=psoriasis RewriteRule^(+)category/(++)$/$1 category.php5?category=$2[L],它不会起作用。这是一条如此简单的规则!谢谢,这是很好的建议。我会去做的,然后再给你回复-特别是,+是一个非常好的主意。好的,我试着将文件剥离为#Translate/category/psoriasis to/category.php5?category=psoriasis RewriteRule^category/(.+)$/category.php5?category=$1[L]并尝试,以防万一#将/category/psoriasis翻译为/category.php5?category=psoriasis RewriteRule^(+)category/(++)$/$1 category.php5?category=$2[L],它不会起作用。这是一条如此简单的规则!