本文介绍了htaccess的国防部重写〜如何修改URL从/pages/pagename.cfm到/页面名/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做一个网站一个网站结构,清理... HTTP://dev.514hebergement。 COM /

I have to do a website structure cleanup on a site... http://dev.514hebergement.com/

找htaccess的指令重写所有网页的URL更友好的URL结构不动,实际网页中的文件夹层次。

looking for the htaccess directive to rewrite all pages url to a friendlier url structure without moving the actual pages in folder hierarchy.

让每一个网页,它是/pages/pagename.cfm在

so every page that is within the /pages/pagename.cfm

将改写其地址/页面名称/

would rewrite its address to /pagename/

和两者/页面名称/和/pages/pagename.cfm网址回应。

and respond to both /pagename/ and /pages/pagename.cfm urls.

让记住我需要的页面名称是动态的,不是硬codeD在htaccess的指令。

lets keep in mind I need the pagename to be dynamic, not hardcoded in the htaccess directive.

非常感谢!

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

my current htaccess is situated in the root of the website:

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

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

the exact address im entering in the address bar is:http://dev.514hebergement.com/pages/hebergement-web-montreal-qualite.cfm

结果URL rewrited到:/页/ hebergement-网络蒙特利尔QUALITE

results in url rewrited to:/pages/hebergement-web-montreal-qualite

我希望它是这样的:/ hebergement-网络蒙特利尔QUALITE /

I want it like this:/hebergement-web-montreal-qualite/

确定,工程...添加斜线到rewrited网址 - >重写规则^ /%1 / [R = 302,L,NE]

OK that works... added the trailing slash to the rewrited url->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文件...

So the last step would be to redirect the root pages to the /pages/pagename.cfm files...

可以说是动态的还是我将不得不单独列出所有网页?

can that be dynamic or will I have to list all pages independently?

推荐答案

您可以在 DOCUMENT_ROOT /的.htaccess 文件中使用此code:

You can use this code in your DOCUMENT_ROOT/.htaccess file:

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]

这篇关于htaccess的国防部重写〜如何修改URL从/pages/pagename.cfm到/页面名/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:56