Bite code
Bite code

Reputation: 597083

Where do you think is best to put URL rewriting?

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

What are the pro and cons ?

Upvotes: 2

Views: 235

Answers (5)

Lincoln
Lincoln

Reputation: 3191

It depends if you also need to do outbound URL-rewriting (the modification of links in the actual HTML pages themselves,) in which case, a tool like MOD_REWRITE will not do the trick for you, and you will need to use an "internal" or "native server-side" tool, in the case of Java, you would use something like PrettyFaces, or Rewrite.

These tools can also do the same type of inbound rewriting (like sending redirects to new pages, or forwarding to a new internal resource so that users do not know they are seeing an address/URL change.

My general rule of thumb, however, is that if the URL-rewrite rules need to be available when the application is running, you should use something like MOD_REWRITE, but if the rules only apply to that application itself, then they belong inside the application and you should use a native tool.

Upvotes: 0

rasjani
rasjani

Reputation: 7970

.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.

Upvotes: 1

Bite code
Bite code

Reputation: 597083

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.

Upvotes: 1

chaos
chaos

Reputation: 124325

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.

Upvotes: 3

Aiden Bell
Aiden Bell

Reputation: 28384

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.

Upvotes: 2

Related Questions