0

我无法让我的 .htaccess 文件正常工作。请有人可以帮我纠正它。

我使用http://htaccess.madewithlove.be/尝试使其正确,但没有成功。

http://www.mydomain.co.uk/bootstrap/rolex-watch.php 应在地址栏中显示为 http://www.mydomain.co.uk/bootstrap/rolex-watch 并显示劳力士手表。页面

http://www.mydomain.co.uk/bootstrap/products.php?f=Watch&b=Tissot&t=T-Touch 应该在地址栏中显示为 http://www.mydomain.co.uk/bootstrap/products/ Watch/Tissot/T-Touch 并显示带有 f 和可选参数 b 和 t 参数设置的产品页面。

.htaccess 文件内容

ErrorDocument 404 /bootstrap/404.php   
ErrorDocument 403 /bootstrap/403.php 

Options +FollowSymLinks
Options +Indexes
RewriteOptions inherit
RewriteEngine on
RewriteRule ^bootstrap/products/(.*)/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5&t=$6
RewriteRule ^bootstrap/products/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5
RewriteRule ^bootstrap/products/(.*)$ bootstrap/products.php?f=$4
RewriteRule ^bootstrap/products/search/(.*)$ bootstrap/products.php?s=$1

Redirect bootstrap/rolex-watch.php http://www.mydomain.co.uk/bootstrap/rolex-watch
Redirect bootstrap/scrap-gold.php http://www.mydomain.co.uk/bootstrap/scrap-gold
Redirect bootstrap/eternity-ring.php http://www.mydomain.co.uk/bootstrap/eternity-ring
Redirect bootstrap/engagement-ring.php http://www.mydomain.co.uk/bootstrap/engagement-    ring
Redirect bootstrap/wedding-ring.php http://www.mydomain.co.uk/bootstrap/wedding-ring
Redirect bootstrap/diamond-ring.php http://www.mydomain.co.uk/bootstrap/diamond-ring
Redirect bootstrap/inferno-diamonds.php http://www.mydomain.co.uk/bootstrap/inferno-    diamonds
Redirect bootstrap/radley-products.php http://www.mydomain.co.uk/bootstrap/radley-products

RewriteRule ^([^\.]+)$ $1.php [NC,L]
4

2 回答 2

0

首先,您的 mod_aliasRedirect指令中有一些杂散空间:

Redirect bootstrap/engagement-ring.php http://www.mydomain.co.uk/bootstrap/engagement-    ring

Redirect bootstrap/inferno-diamonds.php http://www.mydomain.co.uk/bootstrap/inferno-    diamonds

这些将导致 500 服务器错误,因为它具有不正确的 3 个参数。

其次,您的Redirect指令需要与前导匹配/,因此它们都需要看起来像:

Redirect /bootstrap/rolex-watch.php http://www.mydomain.co.uk/bootstrap/rolex-watch

但是这两个问题实际上只是没有实际意义,因为您已经通过使用最后一条规则重写 URI 并通过语句再次重定向来创建重定向循环。Redirect您正在使用的两个不同模块 mod_alias ( Redirect) 和 mod_rewrite ( Rewrite*) 都在 URI 处理管道的不同点应用到同一个 URI,因此它们都破坏了同一个 URI。您需要坚持使用 mod_rewrite 并在开始时添加一个检查以完全防止循环:

# This prevents the rules from looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteRule ^bootstrap/products/(.*)/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5&t=$6
RewriteRule ^bootstrap/products/(.*)/(.*)$ bootstrap/products.php?f=$4&b=$5
RewriteRule ^bootstrap/products/(.*)$ bootstrap/products.php?f=$4
RewriteRule ^bootstrap/products/search/(.*)$ bootstrap/products.php?s=$1

RewriteRule ^bootstrap/rolex-watch.php http://www.mydomain.co.uk/bootstrap/rolex-watch [L]
RewriteRule ^bootstrap/scrap-gold.php http://www.mydomain.co.uk/bootstrap/scrap-gold [L]
RewriteRule ^bootstrap/eternity-ring.php http://www.mydomain.co.uk/bootstrap/eternity-ring [L]
RewriteRule ^bootstrap/engagement-ring.php http://www.mydomain.co.uk/bootstrap/engagement-ring [L]
RewriteRule ^bootstrap/wedding-ring.php http://www.mydomain.co.uk/bootstrap/wedding-ring [L]
RewriteRule ^bootstrap/diamond-ring.php http://www.mydomain.co.uk/bootstrap/diamond-ring [L]
RewriteRule ^bootstrap/inferno-diamonds.php http://www.mydomain.co.uk/bootstrap/inferno-diamonds [L]
RewriteRule ^bootstrap/radley-products.php http://www.mydomain.co.uk/bootstrap/radley-products [L]

RewriteRule ^([^\.]+)$ $1.php [NC,L]
于 2013-09-09T23:02:52.047 回答
0

谢谢乔恩·林,但这对我来说不太管用。

我似乎虚张声势地去做了一些有效的事情。一些我不需要的条目。

由于我没有定义选项,它是否有效地编写?

RewriteEngine on
RewriteBase /bootstrap/

ErrorDocument 404 /bootstrap/404.php   
ErrorDocument 403 /bootstrap/403.php 

RewriteRule ^products/search/(.*)$ products.php?s=$1
RewriteRule ^products/(.*)/(.*)/(.*)$ products.php?f=$1&b=$2&t=$3
RewriteRule ^products/(.*)/(.*)$ products.php?f=$1&b=$2
RewriteRule ^products/(.*)$ products.php?f=$1

RewriteRule ^([^\.]+)$ $1.php [NC,L]
于 2013-09-10T14:21:10.813 回答