English 中文(简体)
我如何用 htaccess 来取代一个语法“_” 表示“/”?
原标题:How do I replace an underscore "_" to a "/" using htaccess?

It is possible to replace the underscore "_" to a "/" using htaccess? Example, I want this http://example.com/empresa_historia-da-empresa.php Stay well http://example.com/empresa/historia-da-empresa

有可能吗?

问题回答

您可以使用这个:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule !.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1/$2/$3/$4/$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1/$2/$3/$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1/$2/$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1/$2 [E=uscor:Yes]

RewriteCond %{ENV:uscor} ^Yes$
RewriteRule (.*) http://example.com/$1 [R=301,L]

Found here (and changed a bit): http://www.askapache.com/htaccess/modrewrite-tips-tricks.html#Rewrite_underscores_hyphens_SEO_URL It will work for 1 to 4 underscroes





相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签