开发者

htaccess regex question - 301 redirect spaces to dash

开发者 https://www.devze.com 2023-03-17 05:38 出处:网络
I\'m just wondering what htaccess mod rewrite regex would be able to redirect any url that contains a space, to t开发者_如何学JAVAhe same URL but a dash in replace of the space.

I'm just wondering what htaccess mod rewrite regex would be able to redirect any url that contains a space, to t开发者_如何学JAVAhe same URL but a dash in replace of the space. For example

I'd want it to redirect any request going from

mysite.com/test/dl/1/the file name.html

to

mysite.com/test/dl/1/the-file-name.html

Is there any way you can do that?


Yes you can, IF:

1) you hard-code such rule (means, you know the file name in advance):

RewriteRule ^test/dl/1/the\sfile\sname\.html$ /test/dl/1/the-file-name.html [R=301,L]

2) you can use RewriteMap and external rewriting program (Perl/bash/etc script) -- see Apache's manual for details (but I personally do not consider this as a very good option).

Otherwise you will have to do it yourself somehow (inside your own website script, for example).

0

精彩评论

暂无评论...
验证码 换一张
取 消