通过php中的htaccess替换url中的?id=和.php

通过php中的htaccess替换url中的?id=和.php,php,.htaccess,url,Php,.htaccess,Url,我想在我的帖子url中用斜杠/替换?id=和.php 我尝试了许多其他问题的答案,但没有像这样对我有效- 我希望这个示例url是这样的 https://example.com/testing/events/news/post/13/Checking-to-see-if-this-works 我使用了下面的htaccess代码,它从url中删除了.php扩展名,但不知道如何将?id=替换为/ RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule

我想在我的帖子url中用斜杠/替换?id=和.php

我尝试了许多其他问题的答案,但没有像这样对我有效-

我希望这个示例url是这样的

https://example.com/testing/events/news/post/13/Checking-to-see-if-this-works
我使用了下面的htaccess代码,它从url中删除了.php扩展名,但不知道如何将?id=替换为/

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
输出-

https://example.com/testing/events/news/post?id=13/Checking-to-see-if-this-works
我仍然无法用替换?id=/

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

感谢您的帮助:)

您可以在站点根目录中使用这些规则。htaccess:

Options -MultiViews
RewriteEngine On

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+(testing/events/news/post)\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^(post)/(.+)/?$ $1.php?id=$2 [L,QSA,NC]

# add .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

我试过这个密码。url发生了变化,但给出了404错误。也许post.php上需要更改一些内容。因为我是这样获得id的-if(isset($\u get['id']){$id=$\u get['id'];}您的htaccess文件位于哪里?它是否在
testing/
目录中?htaccess位于这里-/home/username/public\u html/testing/events/news/.htaccessPosted full.htaccess。确保在测试时没有任何其他规则。它似乎有效。我只是在做更多的测试,以确保它不会破坏任何其他页面URL或创建重复的URL:)写下你“尝试了其他问题的许多答案”&给出一个答案显然不是跟踪研究的情况。你认为这是为什么?(修辞)菲利普西!我可以列出所有答案的链接,但这将是一个很长的列表。:)“列出所有答案的链接”显然不是一个跟踪研究的案例。你显然没有注意到我的反问句或其他问题。然后你想知道为什么你的问题不被接受?(修辞)