我有一个这样结构的网站
index.php/home.php/profile.php/news.php/photos.php
newsfeed.php -用于新闻文章
photo.php - for photo
也有用户名,用户可以获得他的个人资料的短链接,如
mysite.com/UserName
现在我使用。htaccess中的代码重写用户名
的urlRewriteEngine on
RewriteOptions MaxRedirects=1
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ^([^/]+)/?$ profile.php?u=$1 [L]
现在我想重写我所有的链接是se友好的,像这样
index.php --> index
home.php --> home
photos.php --> photos
videos.php --> videos
newsfeed.php?id=xx --> news/xx
photo.php?id=xx --> photo/xx
知道了吗?
我会这样做:
RewriteEngine on
RewriteOptions MaxRedirects=1
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ^users/([^/]+)/?$ profile.php?u=$1 [L]
RewriteRule ^news/([0-9]+)/?$ newsfeed.php?id=$1 [L]
RewriteRule ^photo/([0-9]+)/?$ photo.php?id=$1 [L]
RewriteRule ^videos/?$ videos.php [L]
RewriteRule ^index/?$ index.php [L]
RewriteRule ^home/?$ home.php [L]
然后像这样添加它们