Reputation: 27
I am having issues while using mod_rewrite in an .htaccess file to redirect to another domain.
Here's what I have:
RewriteCond %{HTTP_HOST} ^www.somedomain.com/events_detail/an-event [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory/8559 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^www.somedomain.com [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory [L,R=301,NC]
For some reason www.somedomain.com/events_detail/an-event
I get redirected to http://otherdomain.com/directory
instead of http://otherdomain.com/directory/8559
When testing out my .htaccess on a tester, it indicates that it does not match the first condition but matches the second. I have tried removing the L option, removing the forward ^ without success.
Thank you
Upvotes: 1
Views: 79
Reputation: 41219
RewriteCond %{HTTP_HOST} ^www.somedomain.com$ [NC]
RewriteCond %{THE_REQUEST} /an-Event [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory/8559 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^www.somedomain.com$ [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory [L,R=301,NC]
Upvotes: 1
Reputation: 682
As far as I can see, HTTP_HOST contains only the host name (e.g. www.somedomain.com), and not the complete url. Have you tried using REQUEST_URI or SCRIPT_FILENAME instead?
Upvotes: 0