Php 简单修改重写查询字符串,但仍然失败

Php 简单修改重写查询字符串,但仍然失败,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我想创建.htaccess mod rewrite,但仍然有问题 假设我创建了如下友好URL: mydomain.com/mypage/12345/新闻标题 我希望友好的URL进程隐藏在下面的URL进程中: mydomain.com/index.php?p=mypage&idnews=12345 “p”和“idnews”的值是动态的,因此它们具有不同的值 我尝试了下面的代码,但仍然不起作用。有什么问题吗 RewriteBase / RewriteCond %{QUERY_STRING} p=(\

我想创建.htaccess mod rewrite,但仍然有问题

假设我创建了如下友好URL:

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

我希望友好的URL进程隐藏在下面的URL进程中:

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

“p”和“idnews”的值是动态的,因此它们具有不同的值

我尝试了下面的代码,但仍然不起作用。有什么问题吗

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

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

我想你不需要重写你在那里写的东西

你们可以使用下面的规则

RewriteRule ^/?([0-9a-zA-Z_.-]+)/([0-9]+)/([0-9a-zA-Z_.-]+)$ index.php?p=$1&idnews=$2 [L]

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

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]

错。您正在编写RewriteCond,就好像查询字符串已经被重写一样。把这个拿出来。您的重写规则应该类似于^\/(.*)\/(.*)\/$index.php?p=$1&idnews=$2所以您想将旧查询字符串URL重定向到新的友好URL,对吗?是的,我想将旧查询字符串移动到新的友好URL。然后Ed是正确的,您将其向后移动。您需要寻找新的URL模式,并在内部重定向到index.php。你需要一个例子吗?是的,杰克,我需要一个.htaccess的例子。当我使用这个方法时,生成404找不到的页面。它可以工作。但为什么URL的其他格式会改变呢?例如:“index.php”的主页链接变成“/foo/bar/index.php”。如何使其他URL格式不被更改?@Harris您是否有其他与此冲突的规则?完成。现在已经解决了。而不是像我改为domain.com/index.php“>Home那样使用主页链接