2012-09-05 132 views
1

我有一個網站,它只有3頁的動態url。併爲此我不去php功能。所以我決定去.htaccess重寫規則,但我沒有任何運氣。用htaccess重寫不起作用

這是我的實際網址:/index.php?mode=service&inid=1

我想將它改寫到這一點:/home-theater

我試試我的自我和與此代碼:

RewriteEngine On 

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

Options +FollowSymLinks 
DirectoryIndex index.php 

RewriteEngine On 
RewriteBase/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://www.mysite.com.au/ [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

Options +FollowSymLinks 
RewriteEngine On 
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA] 

我仍然不能讓它工作。

此外,我寫這個代碼之前www重定向index.php,所以我猜如果它導致任何問題或不。 index.php到www網站重定向工作完美,但這是行不通的。

回答

1

使用L標誌是這樣的:

RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA] 

記住這一點,因爲這會在內部將請求轉發給您的index.php不會改變URL在瀏覽器中。

此外,如果這不起作用,然後提供您的問題完整的.htaccess。

更新:我在這裏修改你的.htaccess,請立即嘗試清除瀏覽器緩存後:

DirectoryIndex index.php 

Options +FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase/

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule^http://www.mysite.com.au/ [R=301,L] 

RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA] 

RewriteCond %{ENV:REDIRECT_STATUS} !200 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule^/index.php [L] 
+0

感謝您的答覆,但它不工作。我需要那個瀏覽器和搜索引擎看到家庭影院的url,但服務器從索引url生成頁面。我認爲它可以幫助你。我更新問題,並把我的整個htaccess代碼,如果有幫助。 – Rcreators

+0

我在更新部分修改了.htaccess,請在清除瀏覽器緩存後立即嘗試。還要報告access.log中的相關部分是一個error.log文件。 – anubhava

+0

謝謝。它的工作就像一個魅力。我現在只有一個問題。我有url動態生成。與鏈接。所以我不能編輯網址。現在發生了什麼。上面的url作品,如果我在瀏覽器中寫入。但是當我點擊實際鏈接時,它顯示舊的網址。 – Rcreators