2015-11-04 71 views
1

我想要做的是將請求http://example.com/tel.php重定向到http://example.com/default/index/tel而不顯示任何重定向給用戶。我htaccess的這樣做:用Apache重寫內部URL

RewriteEngine On 

RewriteRule ^tel\.php$ /default/index/tel [NC,L] 


RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

然而重定向顯示了其中我試圖避免用戶(HTTP/1.1 301永久移動)。

如何解決這個問題?

+0

[看這個答案](http://stackoverflow.com/questions/7042234/301-redirect-with-custom-message) –

回答

1

更改你的規則的順序和選擇添加結尾斜槓如果

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteRule ^tel\.php$ /default/index/tel [NC,L] 
# make it as this if /default/index/tel/ is a real directory 
# RewriteRule ^tel\.php$ /default/index/tel/ [NC,L] 

確保清除瀏覽器緩存後對其進行測試。

+1

感謝您的幫助! – Steve