Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_rewrite or mod_alias?

Tags:

I have a server, its httpd.conf already has some "RedirectMatch permanent" directives in it.

I'm not that familiar with mod_alias, I've only ever used mod_rewrite.

What's the basic difference? I don't see a "L" flag in mod_alias to stop processing rules.

Which one should I use for best practices of redirecting from one sub-domain to another?

Can I use both at the same time and will it be obvious which takes precedence?

like image 696
jeph perro Avatar asked Apr 30 '09 17:04

jeph perro


People also ask

What is Mod_alias?

mod_alias. The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot . URLs with a (%-decoded) path beginning with URL-path will be mapped to local files beginning with directory-path . The URL-path is case-sensitive, even on case-insensitive file systems.

What is mod_rewrite?

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. Incoming URLs are checked against a series of rules. The rules contain a regular expression to detect a particular pattern.

What does IfModule mod_rewrite C mean?

The <IfModule mod_rewrite. c>... </IfModule> block ensures that everything contained within that block is taken only into account if the mod_rewrite module is loaded. Otherwise you will either face a server error or all requests for URL rewriting will be ignored.

What is RewriteCond and RewriteRule?

RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive. If we talk about traditional programming RewriteCond works just like 'If' condition where you can use conditions like AND, OR, >=, == , !


2 Answers

mod_alias is basically a simpler version of mod_rewrite. It can't do some things that mod_rewrite can, such as manipulate the query string. If you're able to choose either of them, I don't see any reason that you'd want to use mod_alias.

Is there a specific reason you need to try to use both together?

Apache mod_rewrite & mod_alias tricks you should know seems to be a good article about the two. It notes at one point that mod_rewrite rules get executed before mod_alias ones.

like image 117
Chad Birch Avatar answered Oct 17 '22 12:10

Chad Birch


As the accepted answer says: mod_rewrite can do things which mod_alias can't. However the main benefit of mod_alias is that it is easier to use.

The apache docs say that we should use mod_alias for simple things like redirects and mod_rewrite only for things we cannot do with simpler modules like mod_alias. View the docs: When not to use mod_rewrite.

like image 45
Michael Käfer Avatar answered Oct 17 '22 14:10

Michael Käfer