htaccess 404 redirect with postdata

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

htaccess 404 redirect with postdata

Post by jollyjumper »

Hi Everyone,

I'm starting to develop a general basis for multi language sites, so I don't have to develop it again and again every time I need it.

My idea is to have a file called handler.php which is connected to the 404 event in a .htaccess file.

All other files are in the root folder, like contact.php.
When I want a english version of the contact.php I call /en/contact.php. Because the /en folder doesn't exists, it calls the handler.php. This should execute a regex over the redirect_url to get the language and the file called.

Question 1: Is this a smart way to handle, or are there better ones?
Question 2: How do I get the POST and GET vars in the handler.php right, like it would just as the file handler.php was called directly.

Hope this is an understandable story :-)

Thanks in advance.

Greetz Jolly.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

I'd suggest to reverse your scheme:
contact.php/en/

This approach is called `user-friendly urls`
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Weirdan,

Thanks for your reply.

I've taken a look at the link you posted, and this is indeed the way I want to handle other websites in the near future(was looking for this actually :-)), but it isn't the sollution for my current problem, at least in my opinion.

What I want to create is a multilanguage base for my websites.
The pages should know what language has been selected without any use of sessions or cookies.

But another very important thing is that I absolutely don't want to do anything special for it in my html, like adding ?lang=en in links, and hidden input fields in my forms.

This is why I came up with the virtual subfolder idea. The relative links will always point to the subfolder(in this case a virtual subfolder), so the language is automatically taken up in a link. The same is for the action variable of a form field.

In my mind the problem with reversing the url, is that all relative links will automatically go to the subfolder contact.php. If I'm mistaken please correct me :-)

Greetz Jolly.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

jollyjumper wrote: In my mind the problem with reversing the url, is that all relative links will automatically go to the subfolder contact.php. If I'm mistaken please correct me :-)
Yeah, they will. But you can create say, `main` file in your Document_root then set ForceType to application/x-httpd-php for this file and then you can use the link http://www.yoursite.com/main/en/something.html. This will give you in $_SERVER['PATH_INFO'] '/en/something.html' and relative link, say <a href='something_else.html>link</a> in something.html will point to http://www.yoursite.com/main/en/something_else.html.
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Weirdan,

Thank you for your reply.

I've did something like you've described, only then with mod_rewrite. But your idea has inspired me to do this.

Thanks a lot.

If people are interested in the rewriterules for doing this I can post them here next week.

Greetz Jolly.
Post Reply