2012-07-31 98 views
0

我寫.htaccess文件轉換網址,搜索引擎友好:的.htaccess URL重寫不工作

原始URL是:

http://palestinianz.com/?page=person&p=Alex-Atalla 

的.htaccess的內容是:

RewriteEngine On 
RewriteRule ^([^/]*)\.html$ /?page=person&p=$1 [L] 

它應該產生這樣的鏈接:

http://palestinianz.com/Alex-Atalla.html 

但是,儘管我把文件放在我的網站的根目錄下,但它沒有任何效果! 問題在哪裏?

回答

0

如果你想要的網址在地址欄中改變,你需要重定向瀏覽器,然後在服務器上重寫。這個答案的第一部分介紹了所需的過程:https://stackoverflow.com/a/11711948/851273

所以在看第二個列表,這個過程是將瀏覽器重定向如果一個醜陋的鏈接請求一個很好看的鏈接:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?page=person&p=([^\ ]+) 
RewriteRule ^$ /%1.html? [R=301,L] 

現在,在服務器端,你需要internall改寫回醜陋的網址,這是多了還是少了什麼,你已經有了:

RewriteRule ^([^/]*)\.html$ /?page=person&p=$1 [L] 
+0

謝謝你正在工作!但你能解釋規則嗎? – 2012-07-31 18:56:41

0

你可以試試:

RewriteCond %{REQUEST_URI} (.+)\.html$ 
RewriteRule ^(.+)\.html$ ./index.php?page=person&p=$1 [L] 

只有這個問題是任何.html頁面將通過這一點。可能要更改爲以下內容:

# URL: domain.com/person/Alex-Atalla.html 

RewriteCond %{REQUEST_URI} (.+)/(.+)\.html$ 
RewriteRule ^(.+)/(.+)\.html$ ./index.php?page=$1&p=$2 [L] 

這將讓你有更多的魯棒性改變頁面變量以及

+0

這個代碼 RewriteEngine敘述在 重寫規則^([^ /] *) \ .html $ /?page = person&p = $ 1 [L] wo除了它不會改變地址欄中的網址,我的意思是:加入.htaccess後: http://palestinianz.com/Alex-Atalla.html和 http://palestinianz.com/?page=人&p = Alex-Atalla正在工作 但問題是url仍然是:http://palestinianz.com/?page=person&p=Alex-Atalla在地址欄中! – 2012-07-31 16:23:30