making clean url with htaccess

2019-09-08 07:06发布

I am trying to make clean url with htaccess
I have a profile.php page and I get user domain name to display his page
now if the user for example hit www.XXXX.com/domain I will display his main page
it is equivalent to www.XXXX.com/profile.php?id=domain without htaccess file I used this code and its working very fine

Options +FollowSymLinks
RewriteEngine On
RewriteCond %(SCRIPT_FILENAME) !-d
RewriteCond %(SCRIPT_FILENAME) !-f
RewriteRule ^(\w+)$ ./profile.php?id=$1
RewriteRule ^(\w+)/$ ./profile.php?id=$1

now I am trying to get page id and the view that the user wants to display but it didn't work

note page id and view are optional values , if didn't found in the url I will display the main page

I want the url to look like www.XXXX.com/domain/pageid/view , which is equivalent to www.XXXX.com/profile.php?id=domain&pid=pageid&v=view

1条回答
We Are One
2楼-- · 2019-09-08 07:22

This should do it:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %(SCRIPT_FILENAME) !-d
RewriteCond %(SCRIPT_FILENAME) !-f
RewriteRule ^(\w+)\/(\w+)\/(\w+)\/?$ ./profile.php?id=$1&pid=$2&v=$3
查看更多
登录 后发表回答