Forum Moderators: phranque

Message Too Old, No Replies

How to redirect domain to deeper path?

         

nvautier

10:07 pm on Feb 26, 2006 (gmt 0)

10+ Year Member



I would like to redirect a parked domain to a deeper path. Similar to how amazon redirects a user to a deeper sub-directory. My only attempts at this have resulted in a permenant loop. Any help appreciated.

extras

2:57 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



Do you mean something like this?
[webmasterworld.com...]

You can find tons of examples with google and other SE:
[google.com...]

I wrote several different versions for people with different needs.
If you explain more about what you want, what you have tried,
maybe I can suggest one that you may like.

nvautier

9:44 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



Perfect, I found this from the google search...

RewriteBase /
RewriteCond %{HTTP_HOST} parked-domain
RewriteCond %{REQUEST_URI}!subdirectory/
RewriteRule ^(.*)$ subdirectory/$1 [L]

extras

11:40 pm on Mar 1, 2006 (gmt 0)

10+ Year Member



Oh, you found one of the bad quality example ....
This is the improved version of that code, if you care.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain\.com$ [NC]
RewriteRule !^/*subdirectory/ subdirectory%{REQUEST_URI} [L]

If you want subdomains of that parked domain to go to the same directory:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+\.)?parked-domain\.com$ [NC]
RewriteRule !^/*subdirectory/ subdirectory%{REQUEST_URI} [L]

Also, you want to use the fix for missing trailing slash problems
if you use the domain name with 'www'.
(Put it before other Rules.)
RewriteRule ^/*(.+/)?([^.]*[^/])$ [%{HTTP_HOST}...] [L,R=301]

If you want to cover both http and https:
RewriteCond s%{HTTPS} ^((s)on¦s.*)$ [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]

Note: These codes are efficient compared to the code with '-d' check,
but they won't work with directories that have a dot (period) in it.
(ex. /a_directory.name/)

jdMorgan

1:36 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't end-anchor domain names used in RewriteConds.

"parked.domain.com:80" is a perfectly-valid value for HTTP_HOST, and will break your rule if the hostname is end-anchored after ".com".

Use:


RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain\.com [NC]

or

RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain\.com(:[0-9]+)?$ [NC]

or

RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain\.com(:[0-9]{1,5})?$ [NC]

instead.

You can use any Mozilla-based browser to test this appended-port problem.

Jim

extras

2:42 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



That's true.
Thank you for reminding me. :)