apache - 重写 .htaccess 中的 URL,用正斜杠(id?=value)替换查询参数

标签 apache .htaccess mod-rewrite url-rewriting

我已经确保重写引擎已启用并且删除 .php 扩展名正在工作,所以我知道这不是问题。
我想要做的只是删除 URL 的 ?id=value 方面,因此基本上使 URL 看起来像这样:

folder/medias/value
代替
folder/medias?id=value
我当前的 .htaccess 看起来像这样:
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

RewriteRule ^404/?$ /404.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^ 404.php [L,R]

最佳答案

使用您显示的示例/尝试,请尝试遵循 htaccess 规则。在测试您的 URL 之前,请确保清除浏览器缓存。

RewriteEngine ON
##Rules for external rewrite.
RewriteCond %{THE_REQUEST} \s/([^.]*)\.php\?id=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Rule for internal rewrite.
RewriteRule ^([^/]*)/([^/]*)/?$ $1?id=$3 [L]

关于apache - 重写 .htaccess 中的 URL,用正斜杠(id?=value)替换查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67936561/

相关文章:

web-services - 服务器超时问题

.htaccess - 使用 htaccess 将所有域别名重定向到一个

.htaccess - 将 web.config 文件转换为 .htaccess

.htaccess - HTACCESS RewriteRule 更改 URL 正常但给出 404 页面

apache - 强制删除 .htaccess 中的 .php 扩展名

spring - org.apache.catalina.LifecycleException : A child container failed during start

regex - .htaccess:重定向除一个页面之外的所有页面

apache - 让 CGI 脚本使用 Apache 捕获对域的所有请求

php - 启用 .htaccess 时 Joomla 3.8 出现 404 错误

php - 从 htaccess 中删除 php 扩展,但保持 PATH_INFO 功能