Thursday, 15 July 2010

apache - Simple modrewrite to remove particular part of path -


I am trying to create a modrewrite rule that will change:

/ Blah / right / xyz.htm

to

/correct/xyz.htm

not always Blah but when it's there, it always appears in the beginning of the URL. URL can be any length with many sub-paths, it may also be /blah/myfile.htm (which should only be rewritten to /myfile.htm ).

What is the best way to do this?

After

enable mod_rewrite and .htaccess via httpd.conf and then Put this code under your code in your .htaccess DOCUMENT_ROOT directory:

  option + RewriteBase / RewriteRule RewriteEngine ON (Turn on FollowSymLinks -MultiViews # Mod_rewrite ?: ^ | /) blah (/.+)$ / $ 1 [L, nc]   

This will be internally forwarded to / blah / foo / foo or / blah / correct / foo to / correct / foo . If you want external rewrite then use:

  rewrite (: ^ | /) blah (/.+)$ / $ 1 [L, R = 301, nc]    

No comments:

Post a Comment