2013-10-28 83 views
1

我想重写一个URL,我不希望现有链接再转到旧页面(地址)。重定向并重写URL htaccess

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 

这不起作用 - 就好像这条线不存在一样。请有任何想法吗?

回答

1

两件事:

  1. 规则的排序非常重要,所以有301的内部重写之前
  2. 不要mod_rewrite

下面的代码应该为你工作混mod_alias规则:

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] 
+0

感谢您的提示,您是否能够发布一个例子它应该是什么样子?非常感谢:) – Tim

+0

@Tim:刚刚使用示例代码进行编辑。 – anubhava

+0

美丽。谢谢*非常* @anubhava – Tim