apache - .htaccess 和 mod_rewrite 帮助

标签 apache .htaccess mod-rewrite

使用 mod_rewrite,我如何转换遵循此模式的 URL:

http://example.com/index.php?id=14

进入这个模式:

http://example.com/14/

最佳答案

因为我认为您更想将请求重写为 /<ID>/内部到/index.php?id=<ID> ,试试这个:

RewriteRule ^(\d+)/$ index.php?id=$1

但是如果你真的想将请求重定向到 /index.php?id=<ID>内部到/<ID>/ :

RewriteCond %{QUERY_STRING} (^|&)id=(\d+)(&|$)
RewriteRule ^index\.php$ /%2/? [R]

如果您想保留可能的其他 URL 参数:

RewriteCond %{QUERY_STRING} ^(([^&]*&+)*)id=(\d+)(&+(.*))?$
RewriteRule ^index\.php$ /%3/?%2%5 [R]

关于apache - .htaccess 和 mod_rewrite 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2260440/

相关文章:

java - 由 : org. apache.axis2.AxisFault 引起:无法接合模块:rampart

php - 重定向 .htaccess 文件中的绝对路径

.htaccess - mod_rewrite 和 htaccess

regex - 使用基于查询字符串参数的 HTTP 身份验证保护 url

apache - htaccess - 在子文件夹中使用域强制 SSL 和 www

java - 尝试添加 http 参数但不起作用

http - 用于处理持久 HTTP 连接上的多个请求的 CGI

php - .htaccess seo 重写

PHP openssl_public_encrypt 导致页面超时/连接重置?

.htaccess - 使用 Wordpress 重写多语言网站的规则