简单的mod重写查询字符串,但仍然失败 [英] Simple mod rewrite query string but still failed

查看:99
本文介绍了简单的mod重写查询字符串,但仍然失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建.htaccess mod重写,但是仍然有问题.

I want to create .htaccess mod rewrite but still have problem.

假设我这样创建了友好的URL:

Suppose i created friendly URL like this :

mydomain.com/mypage/12345/新闻标题

我希望该友好的URL在隐藏过程中处理以下URL:

I want that friendly URL process the below URL in hidden process :

mydomain.com/index.php?p=mypage&idnews=12345

"p"和"idnews"的值是动态的,因此它们将具有不同的值.

Values of "p" and "idnews" are dynamic, so they will have different value.

我尝试了下面的代码,但仍然无法正常工作.哪里不对了?

I tried below code but still didn't work. Anything wrong?

RewriteBase /
RewriteCond %{QUERY_STRING} p=(\w+)&idnews=(\d+)
RewriteRule ^index.php /%1/%2 [L,R=301]

任何帮助将不胜感激.抱歉,如果这是重复的问题,如果不介意,请告诉我答案链接.非常感谢.

Any help would be appreciated. Sorry if this is duplicated question, if don't mind please tell me the answer link. Thanks a lot.

推荐答案

如果要将index.php?p=foo&idnews=bar更改为/foo/bar,请尝试以下规则:

If you want to change index.php?p=foo&idnews=bar to /foo/bar , try theses rules :

RewriteEngine on

##externally redirect "/index.php?p=foo&idnews=bar" to "/foo/bar"##
RewriteCond %{THE_REQUEST} /index\.php\?p=([^&]+)&idnews=([^&\s]+) [NC]
RewriteRule ^ /%1/%2? [L,R,NC]
##internally redirect "/foo/bar" to "/index.php?p=foo&idnews=bar"##
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?(.*)?$ /index.php?p=$1&idnews=$2 [NC,L]

这篇关于简单的mod重写查询字符串,但仍然失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆