easyphp .htaccess rules
Asked Answered
H

1

7

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

Hurdygurdy answered 5/1, 2012 at 2:30 Comment(0)
G
11

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

Greisen answered 5/1, 2012 at 2:35 Comment(1)
yes, just make sure the mod_rewrite is enable and you should be all set.Greisen

© 2022 - 2024 — McMap. All rights reserved.