Reputation: 25
Using a RewriteRule I'm trying to redirect every url in a subdirectory to another subdirectory as an absolute path, trimming anything that came after the first directory. Example:
www.domain.com/store/search
www.domain.com/store/search?search=some_term
etc.
all need to go to
www.domain.com/newdir/
unfortunately the results I am seeing are like such:
www.domain.com/store/newdir/
www.domain.com/store/newdir/?search=some_term
and so on. I am using this command currently:
RewriteEngine on
RewriteRule search(.*) newdir/ [R=301,NC,L]
How can I redirect anything in /store/search to just simply /newdir, trimming anything that comes after the word "search"? Thanks.
Upvotes: 1
Views: 780
Reputation: 776
If the .htaccess is in the root directory you can do something like this
RewriteEngine on
RewriteRule ^store/search(.*)?$ ./newdir/$1 [R=301,NC,L]
Or if the .htaccess is in the "store" directory you could do this...
RewriteEngine on
RewriteRule ^search(.*)?$ http://www.domain.com/newdir/$1 [R=301,NC,L]
The above is to keep the query strings, if you want to just redirect to the directory remove the $1
Upvotes: 1