how can I rewrite URL to fancy url?

[亡魂溺海] 提交于 2019-12-11 06:36:56

问题


when my user logs in, I want the get variables that were sent rewrote onto the URL like so:

http://mysite.com/mygetvar1/mygetvar_value1/mygetvar2/mygetvar_value2/

or

mysite.com/mygetvar1=mygetvar_value1/mygetvar2=mygetvar_value2/

How can I do this? Please help! Thanks!


回答1:


Codeigniter can offer you like that. Many other PHP frameworks offer that as well.




回答2:


Try this.

RewriteRule /([^/]*)/([^/]*)/([^/]*)/([^/]*)/ /login.php?$1=$2&$3=$4 [R=301]
RewriteRule /([^/]*)=([^/]*)/([^/]*)=([^/]*)/ /login.php?$1=$2&$3=$4 [R=301]



回答3:


First you need the mod_rewrite module enable.

After, put this in your config file :

RewriteEngine on
RewriteRule ^ads/(rims|tires|combo)/([0-9]+)/(.+).html     /ad.php?noAds=$2 [L,QSA]

This is a example. Your url will look like : http://www.yourwebsite.com/ads/rims/331/title.html but you will call the url : http//www.yourwebsite.com/ad.php?noAds=331

For your regex , you should use a site like http://www.rubular.com

You can use the .htaccess file or put in directly in the httpd.conf file



来源:https://stackoverflow.com/questions/3740229/how-can-i-rewrite-url-to-fancy-url

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