Home > Software design >  How to rewrite a space ( ) in .htaccess
How to rewrite a space ( ) in .htaccess

Time:10-12

I am trying to get some old URL's to redirect to the homepage. I tried it like below but it doesn't appear to work. Also tried some regex, but no results.

RewriteRule ^blog/ article name(/?)$ / [R,L]

How is this to be done?

CodePudding user response:

Converting my comment to answer so that solution is easy to find for future visitors.

To be able to match whitespace in URI, you can use perl property for whitespaces \s in your rule like this:

RewriteRule ^blog/\sarticle\sname/?$ / [R=302,NC,L]

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

  • Related