Forum Moderators: phranque
Was wondering if someone could help me... I don't really understand mod_rewrites and the like (I tend to just gain what I can from forums and cobble it together!) and can't find a solution to this problem.
Whenever a URL starts with:
www.domain.com/path1/rest-of-the-path...
I want it to redirect to:
www.domain.com/path2/rest-of-the-path...
Some examples:
www.domain.com/path1/ TO www.domain.com/path2/
www.domain.com/path1/tags/ TO www.domain.com/path2/tags/
www.domain.com/path1/tags/x/y/z TO www.domain.com/path2/tags/x/y/z
www.domain.com/otherpath UNAFFECTED
Can anyone help me?
Thanks in advance and sorry for being such a newbie,
Guy
Just thought, maybe better explained using pseudo code. I need a rule that does this:
If domain starts with [domain.com...] ...
Then change it to [domain.com...] ...
I know it's no doubt simple, but don't have a clue how to do it :-(
Regards,
Guy
That is not a domain, it is a domain followed by a URL-path.
This is a basic redirect/rewrite question, already well-covered in the mod_alias [httpd.apache.org] and mod_rewrite [httpd.apache.org] documentation.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
I looked at the documentation but I don't understand it. My best attempt is:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^http://www.example.com/tag/ [NC]
RewriteRule ^(.*)$ http://www.example.com/category/$1/ [L,R=301]
So if the URL starts with http://www.example.com/tag/, change it to read http://www.example.com/category/
This should mean that, for instance, http://www.example.com/tag/apache becomes http://www.example.com/category/apache but I think I've done something wrong?
Can anyone help?
Thanks,
Guy
www.domain.com/path1/ TO www.domain.com/path2/
www.domain.com/path1/tags/ TO www.domain.com/path2/tags/
www.domain.com/path1/tags/x/y/z TO www.domain.com/path2/tags/x/y/z
www.domain.com/otherpath UNAFFECTED
RewriteEngine on
#
RewriteRule ^path1/(.*)$ http://www.example.com/path2/$1 [R=301,L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim