是否可以创建一个漂亮的网址,而无需触摸文件本身?例如:
http://sawebdev01/company/news-events/press-releases/press-release/?pr=168#.Uajh_kCyBSK
并将其转换为:
http://sawebdev01/company/news-events/press-releases/pr/168
我试过这个,但它似乎不起作用:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} /company/news-events/press-releases/press-release/?pr=([^&]+) [NC]
RewriteRule .* /company/news-events/press-releases/press-release/pr/%1? [R=301,L]
答案 0 :(得分:0)
试试这段代码:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s(/company/news-events/press-releases)/press-release/\?pr=([^&]+) [NC]
RewriteRule ^ %1/pr/%1? [R=302,L]
RewriteRule ^(company/news-events/press-releases)/pr/([^/]+)/?$ /$1/press-release?pr=$2 [L,NC,QSA]