1 回答
TA贡献1784条经验 获得超8个赞
用这个里面替换你的代码/ecommerce/.htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /ecommerce/
##HERE IS THE IMPORTANT PART
RewriteCond %{THE_REQUEST} /product\.php\?name=([^&\s]+) [NC]
RewriteRule ^ product/%1/? [L,R=301]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index|(\S+?))\.php[/\s?] [NC]
RewriteRule ^ /%1%2 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?product/([^/]+)/?$ product.php?name=$1 [L,NC,QSA]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
确保在新浏览器中测试它以避免旧浏览器缓存。
- 1 回答
- 0 关注
- 150 浏览
添加回答
举报