Reputation: 722
I have urls like www.example.com/de/something
and I need to redirect to www.example.com
everything that starts with /de/
.
At the moment I have done this
redirect 301 /de http://example.com
and it redirect all links but just removing /de
part and result is www.example.com/something
.
How to fix this?
Thanks
Upvotes: 1
Views: 26
Reputation: 2900
If you want /de/ in the target you should have specified so, becasue Redirect will include in the target everything "after" what you have matched.
For a different virtualhost as the destination you want this:
Redirect 301 /de/ http://example.com/de/
or
Redirect 301 /de http://example.com/de
If what you want is redirect inside the same virtualhost /de to /, then use a negative lookahead.
RedirectMatch ^(?!de) http://example.com/
If the context is .htaccess, for virtualhost It would be:
RedirectMatch ^/(?!de) http://example.com/
Note: I use /de/ originally because that's what you describe in your question, and also I match slashes in the target. Both source and target without slashes would be fine too for cases like /desomething or /de/something. In any case, always match slashes or the lack of them.
Note2: Do not use .htaccess to redirect unless you are not the admin of the site. It just complicates things and adds unnecessary overhead since the file/s need to be checked a number of times per hit.
Upvotes: 0
Reputation: 41249
redirect directive matchs rest of the uri and appends it to the target, you can use RedirectMatch to redirect a specific uri
redirectMatch 301 ^/de/? http://example.com
Upvotes: 1