Php 重写规则更正

Php 重写规则更正,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我花了一整天的时间在这上面,但是我想不出来。这就是我想要的。两者都应该将URL保留为/p/test/或/p/test,而不是实际重定向到/p.php?slug=test(与标记相同) 到目前为止,我所尝试的: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^p/([a-z]+)$ p/$1/ [L] RewriteRule ^p/([a-z]+)/$ p.php?slug=$1 [L] RewriteRule

我花了一整天的时间在这上面,但是我想不出来。这就是我想要的。两者都应该将URL保留为
/p/test/
/p/test
,而不是实际重定向到
/p.php?slug=test
(与标记相同)

到目前为止,我所尝试的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^p/([a-z]+)$ p/$1/ [L]
RewriteRule ^p/([a-z]+)/$ p.php?slug=$1 [L]

RewriteRule ^tag/([a-z]+)/?$ tag/index.php?tagID=$2 [L]  
第二个例子:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^p/([a-z]+)$ p/$1/ [L]
RewriteRule ^p/([a-z]+)/$ p.php?slug=$1 [L]

RewriteRule ^tag/([a-z]+)$ tag/$2/ [L]
RewriteRule ^tag/([a-z]+)/$ /tag/index.php?tagID=$2/ [L]  
最后一个例子:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^p/([.*])$ p/$1/ [L]
RewriteRule ^p/([.*])/$ p.php?slug=$1 [L]

RewriteRule ^tag/([.*])/?$ tag/index.php?tagID=$1 [L]
除第一个示例第一条规则(第3行和第4行)外,其中没有一条工作正常。即使有问题,/p/test也与/p/test/不同,但没有任何错误迹象

下面是继续tagID参数的函数(它工作正常):


本文件如下:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^tag/([^/]+)/?$ /tag/index.php?tagID=$1 [QSA,L]

RewriteRule ^p/([^/]+)/?$ /p.php?slug=$1 [QSA,L]
重定向example.com/p/test/->example.com/p.php?slug=test 重定向example.com/p/test->Object not found错误

重定向example.com/tag/sometag/>未找到对象错误 重定向example.com/tag/sometag->Object not found错误

现在,有件事我想告诉你,请不要责怪我,但我不希望上面的URL重定向到我在顶部写的页面,而只是重写它们(DoQuery)。例如:
example.com/p/test/
->不应重定向到
example.com/p.php?slug=test
,而只执行该URL查询(在如何将其称为后端)。URL仍然应该是
example.com/p/test/
(或/p/test)。真的无法更好地解释它。

这应该可以:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?p/([^/]+)/?$ /p.php?slug=$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?tag/([^/]+)/?$ /tag/index.php?tagID=$1 [R=301,L]
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /projects/

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^tag/([^/]+)/?$ tag/index.php?tagID=$1 [QSA,L]

RewriteRule ^p/([^/]+)/?$ p.php?slug=$1 [QSA,L]

没有。这不起作用,浏览器显示“未找到对象”错误。删除/p&/tag前面的斜杠会使它稍微好一点(没有错误,但结尾的斜杠和斜杠会显示不同的页面。还有其他想法吗?您使用了什么URL来测试它?这个.htaccess的位置是什么?还有其他规则吗?我使用了
example.com/post/test/
(和
/post/test
)和
example.com/tag/sometag/
(和
/tag/sometag
)。检查文章的编辑(最后一行下方)到目前为止我所拥有的。我认为它是
/p/
而不是
/post/
这是某种CMS/PHP框架吗?好的,明白了。
/p/
/tag/
是真正的目录吗?里面有更多的规则吗?
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?p/([^/]+)/?$ /p.php?slug=$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?tag/([^/]+)/?$ /tag/index.php?tagID=$1 [R=301,L]
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /projects/

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^tag/([^/]+)/?$ tag/index.php?tagID=$1 [QSA,L]

RewriteRule ^p/([^/]+)/?$ p.php?slug=$1 [QSA,L]