Forum Moderators: phranque

Message Too Old, No Replies

Identifying patterns for URL Rewrites

Need to define URL Rewrites based on domain names

         

Jayaprakash

10:02 am on May 4, 2009 (gmt 0)

10+ Year Member



Hi,

I need to define URL Rewrite rules based on the domain names.

For example,

if the url is "http://www5.jp.com", I need to redirect it to "http://www5.jp.com/Chat/login.jsp"

and if the url is "http://www6.jp.com", I need to redirect it to "http://www6.jp.com/Messages/login.jsp"

How can I identify the domain name and write the Rewrite rule?

Thanks.

Best Regards,
JP.

Jayaprakash

12:21 pm on May 4, 2009 (gmt 0)

10+ Year Member



Hi,

The problem has been resolved.

The syntax is,

RewriteCond %{HTTP_HOST} ^www5.jp.com$
RewriteRule ^/$ [%{HTTP_HOST}...]

RewriteCond %{HTTP_HOST} ^www6.jp.com$
RewriteRule ^/$ [%{HTTP_HOST}...]

Thanks to www.widexl.com.

Best Regards,
JP.

jdMorgan

2:21 pm on May 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be aware that the hostnames may use FQDN notation, may have a port number appended, or both. So we assume that you already have other code that redirects to canonicalize the hostnames if they are non-canonical. Also, you should escape the literal periods in your regular expressions patterns, and always use an [L] flag as shown below.

RewriteCond %{HTTP_HOST} ^www5\.jp\.com$
RewriteRule ^/$ http://%{HTTP_HOST}/Chat/login.jsp [L]
#
RewriteCond %{HTTP_HOST} ^www6\.jp\.com$
RewriteRule ^/$ http://%{HTTP_HOST}/Messages/login.jsp [L]

Jim

g1smd

9:28 pm on May 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The above code generates a 302 redirect.

Is that what you actually want to happen?