Need help with .htaccess, doesn't seem to work
Currently i have url parameters like this http://www.website.com/index.php?user&page=edit
And in index.php i have set if $_GET['user'] is set display user's page and inside user's page i have done something like if $_GET['page'] is set then find the page (in this case edit) and load that page.
It works well.,
But what changes do i need to make in htaccess file such that the url's become like this http://www.website.com/user/ - to load user file and http://www.website.com/user/edit - to load user edit file
Here's my htaccess file content
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)/$ index.php?$1
RewriteRule ^(.*)/(.*)/$ index.php?$1&page=$2
开发者_运维百科But this doesn't seem to work the way i expected.
If i load http://www.website.com/user/edit - it works but if i just load /user/ - it doesn't
Try switching both rules and adding the L-flag:
RewriteRule ^(.*)/(.*)/$ index.php?$1&page=$2 [L]
RewriteRule ^(.*)/$ index.php?$1 [L]
.* matches every character sequence. That means that user/edit/ is matched as well as user/. You need to place the more specific rule first, to make sure that there is a / in between. I suggest that you change that rules to something like this, since the other rules might match stuff that you did not intend:
RewriteRule ^([^/]+)/([^/]+)/$ index.php?$1&page=$2 [L]
RewriteRule ^([^/]+)/$ index.php?$1 [L]
[^/]+ will match every sequence that does not contain any /.
I think the question is already answered - but your rule could be improved.
RewriteRule ^([a-zA-Z]*)/$ index.php?$1
// ...
So it doesn't match / (slashes) and you don't run into that troubles ;-)
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)([^\/.]+)/?$ index.php?$1
RewriteRule ^(.)/(.)/$ index.php?$1&page=$2
Since .* matches anything your first rule will always be applied.
You should use a more specific pattern like [^/]+ (anything but /) instead of .*:
RewriteRule ^([^/]+)/$ index.php?$1
RewriteRule ^([^/]+)/([^/]+)/$ index.php?$1&page=$2
Now the first rule will only be applied on paths with just one segment and the second on paths with twi segments.
加载中,请稍侯......
精彩评论