Apache Mod Rewrite(搜索引擎优化友好的URL';s)
你可能认为我很容易就能在S/O上找到答案,但我已经尝试了一切,在几个小时的挫折之后,我屈服了,看看真正的专家是怎么想的 我“肯定”这可以用mod rewrite完成,但我会听从你的 问题:我正试图打开这样的URLApache Mod Rewrite(搜索引擎优化友好的URL';s),apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,你可能认为我很容易就能在S/O上找到答案,但我已经尝试了一切,在几个小时的挫折之后,我屈服了,看看真正的专家是怎么想的 我“肯定”这可以用mod rewrite完成,但我会听从你的 问题:我正试图打开这样的URL http://domain.com/new-cars/state.php?stateCode=al 至少在这件事上 http://domain.com/new-cars/al-new-cars 不过,理想情况下,我会让它看起来像这样(是的,我愿意重写一些代码,以使用完整的状态名作
http://domain.com/new-cars/state.php?stateCode=al
至少在这件事上
http://domain.com/new-cars/al-new-cars
不过,理想情况下,我会让它看起来像这样(是的,我愿意重写一些代码,以使用完整的状态名作为$stateCode变量,使其更简单!)
最终的计划是能够使用URL的链接,如
http://domain.com/new-cars/alabama-new-cars
并让.htaccess将这个SEO友好的URL与动态版本相关联,并正确显示页面
不管怎样,我都不知道该怎么做
这是我试过的
Options+FollowSymlinks
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^new cars/([^-]*)-new cars/$/new cars/state.php?stateCode=$1[L,QSA,NC]
您可以使用:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+new-cars/state\.php\?stateCode=([^\s&]+) [NC]
RewriteRule ^ /new-cars/%1-new-cars? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^new-cars/([^-]*)-new-cars/?$ /new-cars/state.php?stateCode=$1 [L,QSA,NC]
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+new-cars/state\.php\?stateCode=([^\s&]+) [NC]
RewriteRule ^ /new-cars/%1-new-cars? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^new-cars/([^-]*)-new-cars/?$ /new-cars/state.php?stateCode=$1 [L,QSA,NC]