我无法让我的.htaccess文件正常工作。请有人帮我纠正。
我使用http://htaccess.madewithlove.be/尝试使其正确,但没有成功。
http://www.mydomain.co.uk/bootstrap/rolex-watch.php 应该在地址栏中显示为 http://www.mydomain.co.uk/bootstrap/rolex-watch 并显示rolex-watch.php页面
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]
答案 0 :(得分:0)
首先,你的mod_alias Redirect
指令中有一些杂散空格:
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]
答案 1 :(得分:0)
感谢Jon Lin,但它并不适合我。
我似乎已经虚张声势地做了一些有效的事情。我不需要的一些条目。
是否有效写入,因为我没有定义选项?
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]