【问题标题】:How to remove middle part from URL - mod_rewrite如何从 URL 中删除中间部分 - mod_rewrite
【发布时间】:2013-05-05 07:49:22
【问题描述】:
如何在htaccess文件中将这个url“www.domain.com/index.php?route=custom/static/page”改写为“www.domain.com/page”,基本上就是想取出index.php ?route=custom/static/ 来自 url。
我不知道正则表达式所以我尝试了http://www.generateit.net/mod-rewrite/,但它只生成
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
它不会从 URL 中删除“自定义/静态”,我也尝试了其他一些示例,但只删除了 index.php?并且不传递变量,任何帮助表示赞赏。
【问题讨论】:
标签:
.htaccess
mod-rewrite
【解决方案1】:
你知道使用 mod-rewrite 的概念吗?
在您提到的问题中,您提到使用 mod-rewrite 重定向
"www.domain.com/index.php?route=custom/static/page",
这里$_Get['route']="custom/static/page"]$url_parameter=$_Get['route']
到
"www.domain.com/page" [这里是 $_Get['route']="page"],
所以现在您可以手动将“custom/static/”添加到获得的$_Get['route']. 的值中为$url_parameter="custom/static"+$_Get['route'] //For PHP
使用你的 mod_rewrite 你可以满足你的要求,
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
但如果您需要使用 .htaccess 的开箱即用解决方案,那么我建议您学习“重写引擎”而不是使用生成工具