我想重写一个网址,我不希望现有链接再转到旧网页(地址)。
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^about-us$ /shop/static_page\.php\?static_page_id=3 [NC,L]
这就是我的.htaccess文件目前的样子,它运行正常 - 尽管我添加了一个正常的重定向规则,例如:
Redirect 301 /shop/static_page.php?static_page_id=3 http://example.com/about-us
这不起作用 - 就好像这条线不存在一样。有什么想法吗?
答案 0 :(得分:1)
2件事:
mod_alias
规则与mod_rewrite
以下代码应该适合您:
Options +FollowSymlinks
RewriteEngine on
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+shop/static_page\.php\?static_page_id=3[\s&] [NC]
RewriteRule ^ /about-us? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^about-us/?$ /shop/static_page\.php?static_page_id=3 [NC,L,QSA]