2013-07-15 58 views
1

我做了.htaccess 301重定向以將非www重定向到www,該網址工作正常,但當非www網址訪問網頁時,我的漂亮url丟失。.htaccess - 重定向非www到www網址後丟失的漂亮網址

我已經這樣做了。

Options +FollowSymlinks 
RewriteEngine on 
Rewritecond %{HTTP_HOST} ^site.com [NC] 
Rewriterule ^(.*)$ http://www.site.com/$1 [R=301,NC] 
RewriteRule ^([^/]*)/(.*\.html) process/?category=$1&link=$2 [L] 

它重定向URL

http://www.site.com/software/page.html 

http://www.site.com/process/index.php?category=software&link=page.html 

不正確的地址欄失去相當網址www.site.com/software/page.html

它重定向URL

http://site.com/software/page.html 

http://www.site.com/process/index.php?category=software&link=page.html 

正確,現在漂亮的網址丟失,並且在地址欄中的地址是

http://www.site.com/process/index.php?category=software&link=page.html 

而不是

http://site.com/software/page.html 

如何在沒有www的情況下訪問頁面時保持漂亮的url。

請參閱並提出任何方式來執行此操作。

感謝

回答

2

我認爲問題是缺少L標誌在你的第一個規則。試試這個代碼:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

Rewritecond %{HTTP_HOST} ^site\.com$ [NC] 
Rewriterule ^(.*)$ http://www.site.com/$1 [R=301,NC,L] 

RewriteRule ^([^/]+)/([^.]+\.html)$ /process/?category=$1&link=$2 [QSA,L,NC] 
+0

它沒有工作。 –

+0

你用什麼網址來測試它?並在你的問題中轉儲完整的.htaccess。 – anubhava

+0

我使用了非www網址'http:// site.com/software/page.html'爲'http://www.site.com/software/page.html'工作' –