htaccess mod-rewrite~如何修改/pages/pagename.cfm中的url到/ pagename /

时间:2014-12-18 18:55:35

标签: .htaccess mod-rewrite url-rewriting

我必须在网站上进行网站结构清理...... http://dev.514hebergement.com/

寻找htaccess指令,将所有页面url重写为友好的url结构,而不移动文件夹层次结构中的实际页面。

所以每个页面都在/pages/pagename.cfm

会将其地址重写为/ pagename /

并回复/ pagename /和/pages/pagename.cfm网址。

让我们记住,我需要将页面名称设置为动态,而不是在htaccess指令中进行硬编码。

非常感谢!

我目前的htaccess位于网站的根目录中:

Options +FollowSymLinks
RewriteEngine on    

# DROP THE INDEX FILENAME #
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.cfm($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)INDEX\.CFM($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)INDEX\.cfm($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.CFM($|\ |\?)
RewriteRule ^ /%1 [R=301,L]

# v3 PAGES #
RedirectPermanent /Hebergement-Internet-Montreal/ /
RedirectPermanent /Hebergement-Web-Montreal/ /
RedirectPermanent /Hebergement-Web-Montreal/commander-hebergement.cfm /commander.cfm
RedirectPermanent /hebergement-php.cfm /forfaits-linux.cfm
RedirectPermanent /Hebergement-Web-Montreal/faq.cfm /faq.cfm
RedirectPermanent /Hebergement-Web-Montreal/termes.cfm /termes.cfm
RedirectPermanent /Hebergement-Internet-Montreal/contact.cfm /contact.cfm

# SOLUTIONS-TECHNOLOGIES #
RedirectPermanent /hebergement-linux.cfm /hebergement-web-linux.cfm
RedirectPermanent /hebergement-coldfusion.cfm /hebergement-web-coldfusion.cfm
RedirectPermanent /hebergement-windows.cfm /hebergement-web-windows.cfm
RedirectPermanent /hebergement-mysql.cfm /hebergement-web-mysql.cfm
RedirectPermanent /hebergement-perl.cfm /hebergement-web-perl.cfm
RedirectPermanent /hebergement-php.cfm /hebergement-web-php.cfm


# ARCHIVED PAGES #
RedirectPermanent /Hebergement-Internet-Montreal/promotions.cfm /
RedirectPermanent /promotions.cfm /
RedirectPermanent /hebergement-asp.cfm /forfaits-windows.cfm

我在地址栏中输入的确切地址是: http://dev.514hebergement.com/pages/hebergement-web-montreal-qualite.cfm

导致url重写为: /页/ hebergement-web的蒙特利尔的QUALITE

我想这样: / hebergement-web的蒙特利尔-QUALITE /

确定有效...将重叠的斜杠添加到重写的网址 - > RewriteRule ^ /%1 / [R = 302,L,NE]

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+pages/(.+?)\.cfm[\s?] [NC]
RewriteRule ^ /%1/ [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/pages/$1\.cfm -f [NC]
RewriteRule ^(.+?)/?$ pages/$1.cfm [L]

所以最后一步是将根页面重定向到/pages/pagename.cfm文件......

可以是动态的还是我必须单独列出所有页面?

1 个答案:

答案 0 :(得分:0)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+pages/(.+?)\.cfm[\s?] [NC]
RewriteRule ^ /%1/ [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/pages/$1\.cfm -f [NC]
RewriteRule ^(.+?)/?$ pages/$1.cfm [L]