Forum Moderators: phranque

Message Too Old, No Replies

rewrite rules for parked domain

         

visual

11:55 am on Apr 3, 2008 (gmt 0)

10+ Year Member



Hi, this is my first post, so please excuse me if I write something in a wrong way.

My problem is this
1. I have a main domain www.main.com
2. I have a parked domain www.parked.com. The name server configuration for the parked domain has been done.

Now I need the rewrite rules for the following -
www.parked.com will redirect to www.main.com/user/parked/default/index.html

www.parked.com/files will redirect to www.main.com/user/parked/default/files/index.html

In the www.main.com/user/parked/default directory there are files like index.html,profile.html etc. and also other directories like files,images etc. which also have html files. HTML files in a directory are linked. So in index.html there may be link to profile.html and the link is set like <a href="profile.html">Profile</a>. At present I can do the redirect to index.html with the following rule

RewriteRule ^/?(index.html¦cat)?$ [main.com...]

If I click a link in the index.html file, it does not work. Also I have not been able to figure the rule for redirecting to a sub-directory.

I will really appreciate any help.

Thanks
--visual--

jdMorgan

3:53 am on Apr 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to create and use "back-references," I think... See the mod_rewrite documentation for details.

RewriteRule ^/?(.*)$ http://www.main.com/user/parked/default/$1 [R=301,L]

Jim

visual

8:30 am on Apr 4, 2008 (gmt 0)

10+ Year Member



Thanks Jim. I have not been able to figure out the rules. I am not so familiar with regular expressions. My main problem is to redirect to a sub-folder according to the folder specified in the url. eg.
www.parked.com should go to www.main.com/folder/subfolder/default. I have been able to do this but the links are not working. Also www.parked.com/abc should to go to www.main.com/folder/subfolder/abc. The apache doc is huge and I got lost in it. Can you please give me a link to page or site where I may find redirect rules for this kind of redirects ? I have seen quite a few examples of mod_rewrite but have not found an answer to my particular problem.

Thanks again
--visual--

jdMorgan

1:48 pm on Apr 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See the documents cited in our forum charter and the tutorials in our forum library. Links to both are at the top of this page. Without reading the mod_rewrite documentation and learning the basics of regular expressions, I cannot recommend that you use mod_rewrite; The potential for messing up your server and destroying your search engine rankings by making one little mistake is huge. Don't forget, this code is not some little application script that can crash harmlessly, this is a change to your server configuration.

There are many examples of domain-to-subfolder rewrite threads posted here, some very recent.

Also, if the "parked.com" site is being hosted in the same server space as "main.com," then the rule will need to examine HTTP_HOST so that it only redirects parked.com to "main.com/user/parked" instead of redirecting any host (including main.com) to main.com (this would create an 'infinite' redirection loop). So if all of these domains are hosted in the same server file space, the rule would need to be something like this:


RewriteCond %{HTTP_HOST} ^(www\.)?parked\.com
RewriteRule ^/?(.*)$ http://www.main.com/user/parked/$1 [R=301,L]

Jim

visual

9:51 am on Apr 5, 2008 (gmt 0)

10+ Year Member



Hi jdMorgan,
Thanks a lot for your suggestions. I have used the following rules and they are working to some extent -

RewriteCond %{HTTP_HOST} ^www.parked.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ [main.com...] [R=301,P,L]
RewriteCond %{REQUEST_URI} ^/(.+)\.html$ [NC]
RewriteCond %{REQUEST_URI} !^/(.*)/(.+)\.html$ [NC]
RewriteRule ^(.*)$ [main.com...] [R=301,P,L]
RewriteCond %{REQUEST_URI} ^/user-([0-9]+)/$ [NC]
RewriteRule ^(.*)$ [main.com...] [R=301,P,NC,L]
RewriteCond %{REQUEST_URI} ^/user-([0-9]+)/(.+)\.html$ [NC]
RewriteCond %{REQUEST_URI} !^/user-([0-9]+)/(.*)/(.+)\.html$ [NC]
RewriteRule ^(.*)$ [main.com...] [R=301,P,NC,L]

I am now giving the user directories names like user-1,user-2 etc. These have solved my problems to a great extent and the links are working. Only problem is that www.parked.com/user-1 will not work properly but www.parked.com/user-1/ will work and www.parked.com/User-1/ or www.parked.com/USER-1/ will not work either. In any case I will check these problems and also I have learned the basics of Regular Expressions. I will appreciate any suggestions.

Thanks,
--visual--