I was using something like this...
RewriteRule here/(.*) http://www.there.com/$1 [R=301,L]
but couldn't get it to work
So I used this...
redirect 301 /here http://www.there.com
and it worked fine.
Can someone explain the difference? Do you need both?
Also... how do I exclude paths from the redirect?
Like... redirect 301 all...
redirect 301 /here http://www.there.com
but
/here/stayhere.html
Thanks
L|last. The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed.
The next part is also important since it does the 301 redirects for us automatically: [L, R=301]. L means this is the last rule in this run. After this rewrite, the webserver will return a result. The R=301 means that the web server returns a 301 moved permanently to the requesting browser or search engine.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
RewriteRule is handled by Apache's mod_rewrite, while Redirect is handled by mod_alias. No, you don't need both.
Your RewriteRule (which uses regex) will not match /here
(but will match such paths as /here/foo.html
) because it is looking for a slash immediately after. You can make that optional by using a question mark:
RewriteRule ^here(/?.*) http://www.there.com$1 [R=301,L]
Now that will have the same effect as your Redirect. RewriteCond can be added to exclude certain paths:
RewriteCond $0 !/here/stayhere\.html
Note that some servers do not have mod_rewrite turned on by default. If adding RewriteEngine on
to your configuration does not fix the problem and you cannot switch mod_rewrite on, at least mod_alias provides the RedirectMatch directive, which may be good enough:
RedirectMatch 301 ^/here(?!/stayhere\.html)(/?.*) http://www.there.com$1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With