Forum Moderators: phranque

Message Too Old, No Replies

Redirecting direcotry with wordpress

         

poisons

5:38 pm on Oct 24, 2011 (gmt 0)

10+ Year Member



Hi all I would like to make this:

when I go to www.mysite.fr/blog/ I've to internally point to www.mysite.eu/blog/fr/

The .fr is an alias for .eu, so phisically identical.

Here's the htaccess in the mysite/blog directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{HTTP_HOST} ^www.mysite.fr
RewriteRule (.*)$ /blog/fr/$1 [L]

#WORDPRESS CODE
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>


But with this code Wordpress return a 404 error.

If I try this:
RewriteRule (.*)$ /blog/fr$1 [L]


it will redirect to .eu/blog/fr even in the url, not only internally.

Thanks in advance.

lucy24

2:43 am on Oct 25, 2011 (gmt 0)

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



If I try this:
RewriteRule (.*)$ /blog/fr$1 [L]

it will redirect to .eu/blog/fr even in the url, not only internally.

Well, yes, that's what "redirect" means. If you want it to happen only internally, that's a rewrite.

Here you have made your rewrite into a redirect by putting / at the beginning of the target. This has the same effect in mod_rewrite as it does in mod_alias ("Redirect" by that name): it attaches the first part of the url to the beginning of your rewritten address, changing it into an external redirect. But not the kind of redirect you want.

You need to specify [R=301] in the flag. Otherwise it defaults to 302. And / means "reuse the same path that you came in on" which is precisely what you said you don't want here. So you have to give the complete http://www.example.com.fr ... or .eu or whatever it is.

Or rather, that's what you have to do if you want an external redirect. You say you want a rewrite. Unfortunately your rewritten address lives in a different domain-- even if they are physically in the same place-- which means you are now in [P] proxy territory:

[httpd.apache.org...]

... which in turn means you can disregard this entire post, because I will not touch proxies with a barge pole :( Sorry 'bout that. But you can do some reading in the meantime.

poisons

11:32 am on Oct 28, 2011 (gmt 0)

10+ Year Member



Hi Lucy,
Thanks for your answer.

I tried to put this:
RewriteRule (.*)$ /blog/fr/$1 [L]


and everything works fine.

lucy24

8:32 pm on Oct 28, 2011 (gmt 0)

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



Footnote:

I went back and read the details on RewriteRule very, very slowly and I think I was wrong about the leading / --at least some of the time. That is, it behaves sort-of-but-not-exactly the same as in mod_alias. But the details are so horribly complicated* that it is probably safer to leave off the slash unless you are appending the [R=301] flag.

But you are definitely right about needing to include a slash between "fr" and the $1 capture, because otherwise there will not be one there.


* Really. There's a table that gives something like 36 different permutations of slashes and flags with the meaning of each. I'll go back to the Specific Verbs now, thank you. Those only require four dimensions.