Need help with a RewriteRule - Apache
Here's what I want to do:
http://www.mysite.com/ > http://www.mysite.com/index.php
http://www.mysite.com/asd > http://www.mysite.com/index.php?page=$1
asd
will be the name of the page(s) that get appended to index.php's $page variable.
My curr开发者_JAVA技巧ent rewrite rule successfully redirects the requested page but fails to load the default index.php page.
RewriteEngine On
RewriteRule ^([\w]*)$ /index.php?page=$1 [L]
How do I fix this? :/
You would need to have one rule that matches just the /:
RewriteRule ^/$ /index.php [L]
And then your other one:
RewriteRule ^/([\w]+)$ /index.php?page=$1 [L]
For mine, i simply pass the entire path to the index page.
RewriteRule ^.*$ /index.php?page=$0 [L,QSA]
Then use list()
and explode()
to chunk it up.
list( $param1, $param2, $param3 ) = explode( "/", $_GET['page'] );
Otherwise, you're going to need two rules.
Or use the same rule and on the / page have an empty ?page= parameter.
精彩评论