RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ product.php?ref=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /category.php?sub=$1 [L]
随变量sub发送的值与ref
中的值冲突product.php?ref=$1 [L]
category.php?sub=$1 [L]
答案 0 :(得分:2)
我对任何形式的语义URL的重写规则的建议,即:
/home
而不是
index.php?page=home
制定一条捕获所有网址的规则,例如:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ handler.php?__url=$1 [QSA]
然后让handler.php找出你想要做的事情。
您知道自己的类别和产品,因此如果网址为/[product|category]
,则处理它。
答案 1 :(得分:1)
下面的代码应该有一些改变:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# don't do anything for a valid file or directory
RewriteCond %{ENV:REDIRECT_STATUS} !^$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Product handler /i/test
RewriteRule ^i/([^/]+)/?$ /product.php?ref=$1 [L,NC,QSA]
# PHP handler
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ /$1.php [L]
# category handler
RewriteRule ^([^/]+)/?$ /category.php?sub=$1 [L,QSA]