我想重写http://example.com/test/index.php?id=123
到http://example.com/test/item/123/
和http://example.com/test/index.php?id=123
重定向到人性化的网址。
我不知道我的htaccess有什么问题:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} ^id=([a-z0-9]+)$ [NC]
RewriteRule ^/item/%1/? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/([a-z0-9]+)/$ index.php?id=$1 [L]
答案 0 :(得分:1)
您可以在/test/.htaccess
文件中使用以下RewriteRule
Options +FollowSymLinks -MultiViews
RewriteEngine on
#redirect old url to the new one
RewriteCond %{THE_REQUEST} /test/index\.php\?id=([^\s]+) [NC]
RewriteRule ^ /test/item/%1? [L,R=301]
#internally map new url to the old one
RewriteRule ^item/(.+)/?$ /test/index.php?id=$1 [L,NC]