Reputation: 95
How can I set up mod_rewrite? My directory structure is bellow for(www.example.com)
index.php
user[directory]
index.php [file in user directory]
.htaccess
.htaccess
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?url=$1
How to access http://www.example.com/user
?
When I open http://www.example.com/user
I get http://www.example.com/user/?url=user
How can I solve this problem?
Upvotes: 1
Views: 42
Reputation: 785316
You can use:
# turn directory trailing slash off
DirectorySlash Off
RewriteEngine on
RewriteBase /
RewriteRule ^([\w-]+)/?$ index.php?url=$1 [L,QSA]
# add a trailing slash to directories
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302]
Upvotes: 1