Welcome to WebmasterWorld Guest from 23.20.137.66

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

capturing domain for 301 redirect

     
10:52 am on Aug 3, 2013 (gmt 0)



The site has multiple language domains. The structure is identical same base structure with configurations for each language. Is there a way to generically capture the requesting domain and use that in the rewrite? For example:

RewriteCond %{HTTP_HOST} .
RewriteCond %{REQUEST_URI} ^/products/
RewriteCond %{THE_REQUEST} /([^/]+)/\ HTTP/
RewriteRule /$ {HTTP_HOST}/%1 [R=301,L]


http://www.example.de/products/blah/blah/pencil
to
http://www.example.de/pencil

or

http://www.example.co.uk/products/blah/blah/pencil
to
http://www.example.co.uk/pencil
11:03 am on Aug 3, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Yes, the rule target becomes

http://%{HTTP_HOST}/%1


Be aware this creates a problem in that non-www requests are redirected to non-www and www requests are redirected to www. This means an old request for the non-canonical hostname invokes a two-step (or more) redirection chain.

It is possible to add extra code such that all requests redirect to www in one step, but this gets messy.

Be aware that your example code redirects various URLs that always end with a trailing slash but your URLs presented as examples do not have a trailing slash.
11:16 am on Aug 3, 2013 (gmt 0)



Be aware this creates a problem in that non-www requests are redirected to non-www and www requests are redirected to www. This means an old request for the non-canonical hostname invokes a two-step (or more) redirection chain.

It is possible to add extra code such that all requests redirect to www in one step, but this gets messy.


Would you suggest I implement this rule followed by a new rule redirecting any non www to www?

Be aware that your example code redirects various URLs that always end with a trailing slash but your URLs presented as examples do not have a trailing slash.


Actually this needs fixing in general as both can be used and I will remove trailing /, then implement this rule.
12:15 pm on Aug 3, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Yes, you should have a rule following this one that redirects requests for non-www to to www.

However, this results in a two-step redirection chain for non-www requests. It is better if the first rule also fixes the www at the same time as fixing whatever else it needs to fix.

You still need the general non-www to www redirect in place, as the last rule of all redirects, for all other requests not fixed by earlier rules.
8:19 pm on Aug 3, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



At its simplest: can you have a pair of rules? Here assuming www. is the desired form

RewriteCond %{HTTP_HOST} ^www\.
{et cetera as given, except you don't need the . condition}

and then the identical ruleset again, minus the "www." first condition, with the target given as

http:/ /www.%{HTTP_HOST}/%1

:: wondering if it would be simpler overall to disable autolinking in this subforum :
 

Featured Threads

Hot Threads This Week

Hot Threads This Month