Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect of subfolders

redirect different domains in a wild card type

         

zhaval

9:31 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



Hello,

We have two domain names pointing to one site, but would like the new one with our country's ending (.si) to prevail.

This is how I have corrected the .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.example.si/ [R=301,L]

Redirect works, but it doesn't work as a wild card redirect. Can that also be corrected? For example, calls for www.example.com/info or relative links such as /info give me the 404 error. I would like these calls to point to www.example.si/info, for example.

Thank you very much for your help in advance!

[edited by: jdMorgan at 9:51 pm (utc) on Sep. 20, 2007]
[edit reason] example.com [/edit]

jdMorgan

9:50 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The third RewriteCond, together with a missing back-reference in the rule, rejected anything but your home page. There were several other minor shortcomings. Try this instead:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [OR]
RewriteCond %{HTTP_HOST} ^example\.si
RewriteRule (.*) http://www.example.si/$1 [R=301,L]

The first new RewriteCond accepts either www or non-www. The second new RewriteCond will redirect example.si to www.example.si.

Jim

[edited by: jdMorgan at 9:53 pm (utc) on Sep. 20, 2007]

zhaval

10:14 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



Thank your for your prompt answer! Unfortunately, if I click any of the links on my site or try directly to go to example.com/info (it is now redirected OK to www.example.si/info) I still get

404 Not Found
The requested URL /info does not exist.

Thank you again (I am only a facultative webmaster and appreciate your help enormously!). Best regards.

PS: my previous .htaccess had the following lines which I dropped, is this OK?

RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d

jdMorgan

10:33 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't answer that question... Is that *all* that you dropped?

Also, be sure to completely flush your browser cache before testing any code changes.

Jim

[edited by: jdMorgan at 10:34 pm (utc) on Sep. 20, 2007]

zhaval

10:44 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



I'm sorry, I haver overlooked another line I have dropped:

RewriteRule . /index.php [L]

I cleared the cache.. I get the main page OK, but all of the other subpages are unavailable (Wordpress site).

Thank you again..

jdMorgan

10:51 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, that explains why you are getting 404 errors then. Those pages don't exist as 'real' HTML pages, and are instead generated by index.php. I would suggest putting all of that code back, placing it after the new rules discussed above -- rule order is important.

Jim

zhaval

10:57 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



Fantastic, everything is working now! I am very gratefull, thank you! How does one buy a drink to someone in the cyberworld, I wonder..

Best regards, Damjan