.htaccess to change URL

穿精又带淫゛_ 提交于 2019-12-07 22:38:57

问题


So i have a mvc system setup but it does not generate search engine friendly urls.

A typical url is in the format:

http://sitedomain.com/class/classMethod?parameter=valueA?parameter2=valueB

This is what i need to have:

http://sitedomain.com/class/valueA/valueB/

My .htaccess actually modified a part of the url already but i dont know how to do the second part

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?controller=$1 [L,QSA]

(originally looked like http://site.com/index.php?controller=class, but after the htaccess below is ran, it looks like http://site.com/class)

If anyone could help me with this, that would be great, thank you.


回答1:


RewriteRule ^/class/(.*)/(.*)/$ index.php?controller=class&parameter=$1&parameter2=$2 [L,QSA]



回答2:


I use the following .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$            rewrite.php?%{QUERY_STRING}

And extracting parts from the url is all done in PHP.
Parsing the $_SERVER['SCRIPT_NAME'] variable.

(I find php code much easer to debug than complex apache rewrite rules.)



来源:https://stackoverflow.com/questions/3825989/htaccess-to-change-url

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