Forum Moderators: phranque
I'm fairly new to all this « mod_rewrite » thing but it seems to be the only way to help me with something.
Here's what I have to do :
Let's say I have this website « www.website.com ». I'd like any URLs to point to the same file for 3 URLs (languages) entered. Example : www.website.com/nouvelles.php should be displayed in the adress bar as www.website.com/nouvelles.php BUT use the file news.php to display the content of the website.
In short :
www.website.com/nouvelles.php
www.website.com/destacados.php
www.website.com/news.php
...should use the file « news.php » to display the content BUT the URL should stay as entered.
Is « mod_rewrite » the answer to this?
Thanks a lot for your precious time!
I seem to have a problem thought;
The language is stored in a cookie. Any idea how I could access that information in the .htaccess file to change the URL displayed to (say, spanish as an example) "destacados.php" but use the file "news.php"?
Also, I'd hate to have to change all the links site-wide...!
Thanks.
I have a hard time figuring this one out. Let's break it down:
I need the htaccess to filter every link requests;
If it sees it's a french or spanish cookie identified user;
Change the displayed URL to a language equivalent URL;
Feed the right file.php (not translated)
...
Let's use news.php as an example.
...
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} langue=(Fr) [NC]
RewriteCond %{REQUEST_URI} !^/(news\.php)$
...
is it next -> RewriteRule ^(news\.php)$ /$1nouvelles\.php [NC,L]
?
A Rewrite does not *make* a URL. A rewrite changes nothing on the pages of your site. A rewrite changes nothing out there on the web.A rewrite takes an incoming URL request arriving at your server and silently changes the value for the internal filepath that was hinted at in the URL to be a different internal filepath inside the server, and gets the content from there.
That is, a rewrite takes a URL request for www.example.com/22/44 and instead of the server looking in /var/public_html/www/yoursite/22/44 on the hard disk, the rewrite changes the path part to instead get the content from /var/public_html/www/yoursite/catalog.php?category=22&product=44 without letting anyone back out on the web know that that has happened.
Hmmm... does that mean I'll have to change every link across the website? Please don't say yes...! :(
RewriteEngine On
RewriteBase /
#
RewriteRule ^(nouvelles¦destacados)\.php$ news\.php [L]
You will have to change all links to point to nouvelles.php for French and destacados.php for (Spanish or Portuguese?). Since you are using PHP, this should be fairly trivial to do.
Jim