如何从URL中删除中间部分 - mod_rewrite

时间:2013-05-10 15:12:37

标签: .htaccess mod-rewrite

如何在htaccess文件中将此网址“www.domain.com/index.php?route=custom/static/page”重写为“www.domain.com/page”,基本上只想取出index.php ?route = custom / static / from urls。

我不知道正则表达式所以我尝试http://www.generateit.net/mod-rewrite/,但它只生成

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]

没有从网址中删除“自定义/静态”,我还尝试了其他一些示例,但只删除了index.php?并没有传递变量,任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

你知道使用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”],

现在,您可以将“自定义/静态/”添加到$_Get['route'].获取的值$url_parameter="custom/static"+$_Get['route'] //For PHP

使用您的mod_rewrite可以满足您的需求,

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]

但如果您需要使用.htaccess的开箱即用解决方案,那么我建议学习“重写引擎”而不是使用生成工具