Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

easyphp .htaccess rules

i need to rewrite rules in my installation of easyphp on windows 7.

i need to make sure the rules are loaded correctly and i don't have to create tons of rules. also, when i copy the .htaccess to my server (which is linux) i want to make sure its working properly.

i have no experience with this and here's what i found diging the internet:

RewriteRule (.*) index.php?s=$1

now, if i have basic page like 'contact-us' its ok but if i have sub pages it does not. how can i create sub folders?

thank you

like image 224
Buba Wilson Avatar asked Jan 05 '12 02:01

Buba Wilson


1 Answers

Here's what you need to do:

RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_\-]+)/?$ index.php?main=$1 [NC,L] 
RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/?$ index.php?main=$1&sub=$2 [NC,L]

This will allow you to have pages like:

http://www.domain.com/mainpage/ or
http://www.domain.com/mainpage or
http://www.domain.com/mainpage/subpage/ or
http://www.domain.com/mainpage/subpage

/? Means the slash is optional

[NC] This makes the test case-insensitive - differences between 'A-Z' and 'a-z' are ignored, both in the expanded TestString and the CondPattern. This flag is effective only for comparisons between TestString and CondPattern. It has no effect on filesystem and subrequest checks.

[L] The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed.

All the information about flags and rules: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

like image 178
Book Of Zeus Avatar answered Oct 17 '22 10:10

Book Of Zeus