views:

67

answers:

4

I am a total noob on this issue, and I wonder if I have to do that where I put the code :

  • In the virtual host / apache conf file ?
  • In a httaccess file ?
  • Redirect all URLs to a single entry point and parse it with a scripting language ?

What are the pro and cons ?

+2  A: 

This depends on what exactly you want to do.

Rewriting rules should go in the configuration relating to the directory/site root which is typically your vhost configuration or htaccess (depending on setup).

Doing this through a script only makes sense if your redirect is based on extra information such as matching a 404 to a database of recently moved pages or a 404-URI to a search of some kind.

Aiden Bell
+3  A: 

I'd tend to go with the .htaccess because it's easier to maintain as part of a project's files, doesn't require kicking the web server to take effect, and will typically be faster than scripting-level rewrites.

chaos
A: 

OK, so I put some summary of what I read on SO about it :

URL rewriting for redirection :

Better to put that in the Apache configuration. using .htaccess is the most flexible way but your Apache conf must allow it, if not, set the rewriting in the Vhost file.

URL rewriting for ressource management :

When it's about managing not found contents, access right or getting clean URL for accessing dynamic contents, you need to set the rewriting in the script file of your app since it's where you have access to the API to handle this kind of things.

So both of the ways are complementary, and you will usually use both at the same time.

e-satis
+1  A: 

.htaccess file in the directory should best place if you dont have any speed optimization concerns. And its also the way to go if your site is hosted on shared webhotel or your web application can create the htaccess files by itself.

Personally i prefer to have every configuration option in the virtualhost config file but thats good only if you have the root access.

rasjani