在.htaccess中,我希望像这样重定向urls:
/products.php/a7-frames
/products.php/a6-frames
对此:
/picture-frames/a7-frames
/picture-frames/a6-frames
所以需要用相框代替products.php。在谷歌上搜索了很多之后,我尝试过这样的方法:
RewriteBase /
RedirectMatch 301 (.*)\.php/?$ https://www.domainname.com/picture-frames$1
但是,如果我输入这个url: /products.php/a7-框架,浏览器会说重定向太多了,然后转到:
/picture-frames/index
它正在用products.php来代替画框,这是很棒的,但我不知道为什么它在末尾添加了"index“,而不是url的/a7帧部分?我怎么才能解决这个问题?
发布于 2017-11-09 11:11:14
您可以在站点根.htaccess中使用这些规则:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+products\.php/([^\s?]+) [NC]
RewriteRule ^ /picture-frames/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^picture-frames/([^/]+)/?$ products.php/$1 [L,NC]
在测试此更改之前,请确保清除浏览器缓存。
https://stackoverflow.com/questions/47200002
复制相似问题