.htaccess clean url with more than 3 paramenters

假装没事ソ 提交于 2019-12-04 06:34:25

问题


I am new to .htaccess and I seem to be having some problems getting it to clean up the url for me.

I have

site.com?p=article&id=3&read=article title

I am able to get the first variable to work ok like site.com/articles. but when I try to go further the server is saying it cant find it. I have tried several methods none of which seem to be working.

RewriteRule ^([a-zA-Z0-9]+)$ index.php?p=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?p=$1

this above is working

I have tried

RewriteRule ^([a-zA-Z0-9-z\-]+)(/([a-zA-Z0-9-z\-]+))?/?$ index.php?p=$1&i=$2

and

RewriteRule ^([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)/?$ index.php?p=$1&i=$2&read=$3

the last 2 are not working. help please. Thanks


回答1:


Let's try something like this?

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?p=$1&id=$2&read=$3 [L]



回答2:


%{QUERY_STRING} is what you are looking for.

this is what I use for a similar situation:

RewriteRule   ^/(.*)  /index.php?r=/$1&%{QUERY_STRING} [L]


来源:https://stackoverflow.com/questions/9579231/htaccess-clean-url-with-more-than-3-paramenters

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