Forum Moderators: phranque

Message Too Old, No Replies

MultiLanguage Mod Rewrite

On the same virtual server

         

poisons

10:38 am on May 16, 2011 (gmt 0)

10+ Year Member



Hi,
as in the old post [webmasterworld.com...]
I continue to have problems, the last solution on the post never worked up till now.
Simplifying:
- I've two host, www.example.es and www.example.eu
- The hosts are on the same server, same ip address
- the file come_funziona.php is unique. In the php code I display the proper language in base of the domain extension (Italian for .eu, Spanish for .es).
- Now if I call www.example.es/come_funziona.php it works in Spanish, but I would like to call www.example.es/como_funciona.php redirecting internally to the file come_funziona.php.

The actual htaccess is:

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^landingeu$ /campaign_temp [L]
RewriteRule ^landingeu/$ /campaign_temp [L]


#RewriteCond %{HTTP_HOST} !^example.eu [NC]

#redirect url .eu and .it to http://www.example.eu
RewriteCond %{HTTP_HOST} ^www.example.it [OR]
RewriteCond %{HTTP_HOST} ^example.it
RewriteRule (.*) http://www.example.eu/$1 [R=301,L]

#redirect url without www to http://www.example called extension
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{SERVER_PORT} ^443$x
#rules for admin directory
RewriteCond %{REQUEST_URI} !^/admin/.*

# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.php$
RewriteCond %{REQUEST_URI} !\.json$
RewriteCond %{REQUEST_URI} !\.wsdl$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.swf$

RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.php [QSA]
RewriteRule ^([^.]+)$ $1.php [QSA]
RewriteRule ^dir1/$ http://www.example.eu/dir1/index.php$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]

</IfModule>


Thanks in Advance

g1smd

11:25 am on May 16, 2011 (gmt 0)

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



You need to add the
[L]
flag to EVERY RewriteRule.


RewriteRule ^landingeu$ /campaign_temp [L]
RewriteRule ^landingeu/$ /campaign_temp [L]


The above two rules allow Duplicate Content because requests with or without slash both resolve to content. With slash should be externally redirected to without slash:

RewriteRule ^landingeu/$ http://www.example.eu/landingeu$ [R=301,L]



Additionally, for non-www requests or for non-canonical requests (wrong domain), the external domain redirects later in the file will expose the
/campaign_temp
path back out on to the web as a new URL.

Internal rewrites MUST be listed AFTER external redirects.


This code is problematical:

RewriteRule ^dir1/$ http://www.example.eu/dir1/index.php$1 [R=301,L]


For request
www.example.eu/dir1/
you redirect user to different URL. Never redirect TO a URL with named index file in. Additionally, $1 is undefined in this rule. The
DirectoryIndex index.php
directive would allow you to serve the index file at the
www.example.eu/dir/
URL.


Are the .eu and .es sites in separate folders on the server? If not then
#RewriteCond %{HTTP_HOST} !^example.eu [NC]
redirects
example.es
requests to
www.example.eu
.


RewriteCond %{REQUEST_URI} !\.php$
RewriteCond %{REQUEST_URI} !\.json$
RewriteCond %{REQUEST_URI} !\.wsdl$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.swf$


simplifies to:

RewriteCond %{REQUEST_URI} !\.(php|json|wsdl|gif|swf)$



[QSA]
is the default action and does not need to be specified. The
[L]
flag is required here.


Due to odd line spacing, the code is difficult to read. The only blank lines should be AFTER each and EVERY RewriteRule.


There are likely to be other problems with the code.

poisons

2:22 pm on May 16, 2011 (gmt 0)

10+ Year Member



Thanks for your reply
the .eu and .es are in the same folder.

I've posted the code of the actual htaccess.
What I do now, in sequence, is:
- redirecting internally to /campaign_temp when you write /landingeu. I'll delete these two rules and manually rename the /campaign_temp to /landingeu
- Redirect the non www to www and the .it to .eu
- the others directives were put there directly by the symfony framework.

Maybe it would be better to proceed step by step.
Now the htaccess appears this way:

Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On

#redirect url .eu and .it to http://www.example.eu
RewriteCond %{HTTP_HOST} ^www.example.it [OR]
RewriteCond %{HTTP_HOST} ^example.it
RewriteRule (.*) http://www.example.eu/$1 [R=301,L]

#redirect url without www to http://www.example.called_extension
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

# we skip all files with .something
RewriteCond %{SERVER_PORT} ^443$x
RewriteCond %{REQUEST_URI} !^/admin/.*
RewriteCond %{REQUEST_URI} !\.(php|json|wsdl|gif|swf)$
RewriteRule .* - [L]

# we check if the .html version is here (caching)
RewriteRule ^$ index.php [QSA]
RewriteRule ^([^.]+)$ $1.php [QSA]

# no, so we redirect to our front web controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>


Now, my big purpose at the moment is to mask the master file come_funziona.php with a multilanguage name.
Start from spanish.
When I call www.example.es/como_funciona.php, internally the server has to redirect to www.example.es/come_funziona.php.

Is this possible?

Thanks in advance,