making clean url with htaccess

爱⌒轻易说出口 提交于 2019-12-25 08:19:21

问题


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:


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


来源:https://stackoverflow.com/questions/9804992/making-clean-url-with-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!