2012-10-08 53 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/