2016-10-19 54 views
0

我有以下網址:的mod_rewrite:URL重寫和重定向

http://example.com/pages/cms/impressum.php 

,並希望得到像這樣的URL:

http://example.com/impressum 

我重寫規則是:

RewriteEngine on 
RewriteBase/
RewriteRule ^impressum$ /pages/cms/impressum.php [R,L] 

問題是,我可以用兩種方式打開網址。我想從/pages/cms/impressum.php轉到/ impressum。如果我使用[R = 301],我不想要的第二個URL。我想扭轉這個規則。

回答

1

用途:

RewriteEngine On 
RewriteBase/

# To externally redirect pages/cms/impressum.php to impressum 
RewriteCond %{THE_REQUEST} \s/+pages/cms/impressum\.php[\s?] [NC] 
RewriteRule^/impressum [R=301,L] 

# To internally forward impressum to pages/cms/impressum.php 
RewriteRule ^impressum/?$ pages/cms/impressum.php [L,NC] 
+1

非常感謝。有用 –