2012-10-08 103 views
0

可能重複:
.htacces to create friendly URLs. Help neededWordPress的像.htacces漂亮的URL

我想建立像WordPress的腳本爲 「漂亮的網址」,我複製的.htaccess行和製作一些修改,但在PHP的一邊,我不知道如何建立它。

我不明白它是如何工作的。

+0

我去了你提供的鏈接,但我不明白如何做到這一點在PHP端... –

+1

看看接受的答案。 –

+0

好吧,我明白了,但我想知道WordPress腳本如何工作... –

回答

1

開始設置重寫引擎,並按照符號鏈接

RewriteEngine On 

# Drop the .php -- or any other extension you use. 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

#Forces the site to switch to www.site.com - change the site/TDL below 
RewriteCond %{HTTP_HOST} ^insuranceiwant\.com$ 
RewriteRule (.*) http://www.insuranceiwant.com/$1 [R=301,L] 

現在,如果你拉從動態頁面命名您的網頁像site.com/contact-us 有用數據庫,還加上這個:

Options +FollowSymLinks 
Options +Indexes 
RewriteRule ^([A-Za-z_]+)_([A-Z]+)/([A-Za-z0-9_-]+)$ /Resources/city.php?state=$1&region=$2&city=$3 

這個例子說明動態頁面有一個狀態名,狀態爲abbr eviation,以及城市從數據庫中提取,並顯示如下所示的頁面: insuranceiwant.com/California_CA/Los_Angeles

有關爲您的頁面名稱正規表示法的更多信息請查看本有用的網站: http://www.regular-expressions.info/