Alex Rivera | Logout

.htaccess and params

Asked 2012-01-03T02:18:25.270
14

i digg on the internet about .htaccess and rewrite rules i need to do with my site.

i saw something i dont understand and want to know what it means

i am wondering what is the difference between the 2 regular expression that i need to use for my site among all others i need to use):

RewriteRule ^home$ mainpage.php?id=$1 [QSA]

and

RewriteRule ^home(/)?$ mainpage.php?id=$1 [L]

i looked at the QSA and L but what the (/) means?

Edit
Report

1 Answer

18

The expression will be (/)? not (/). It means slash or not on the URL. These two URLs will go to the same place:

http://www.domain.com/home/

and

http://www.domain.com/home

So the slash is optional. This way, if a bot or a search engine puts it, the rule will work.

You can rewrite the rules like this:

RewriteRule ^home/?$ mainpage.php?id=$1 [L,QSA]

Also, I saw you said:

among all others i need to use

If all your pages goes to the same file (in this case mainpage.php), you can create one rule that will automatically rewrites them instead of creating 10 or 15 rules (or more). You can do this like this:

RewriteEngine on
REwriteBase /
RewriteRule ^([a-z0-9\-_]+)/?$ mainpage.php?id=$1 [L,QSA]

This rule will use Letters, Numbers, Dash and Underscores as the page.

answered 2012-01-03T02:29:01.087

Your Answer