简体   繁体   English

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

[英]How to remove middle part from URL - mod_rewrite

How to rewrite this url "www.domain.com/index.php?route=custom/static/page" to "www.domain.com/page" in htaccess file, basically just want to take out index.php?route=custom/static/ from urls. 如何在htaccess文件中将此网址“www.domain.com/index.php?route=custom/static/page”重写为“www.domain.com/page”,基本上只想取出index.php?route =自定义/静态/来自网址。

I don't know regex so I tried http://www.generateit.net/mod-rewrite/ , but it only generates 我不知道正则表达式,所以我尝试了http://www.generateit.net/mod-rewrite/ ,但它只生成

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

which doesnt remove 'custom/static' from URLs, I tried a few other examples as well but only removes index.php? 哪个不从URL中删除'custom / static',我还尝试了其他一些例子,但只删除了index.php? and doesnt pass variable, any help is appreciated. 并没有传递变量,任何帮助表示赞赏。

Do you know the concept of using mod-rewrite? 你知道使用mod-rewrite的概念吗?

In your question you have mentioned to use mod-rewrite to redirect 在您提出的问题中,您提到使用mod-rewrite进行重定向

"www.domain.com/index.php?route=custom/static/page", Here $_Get['route']="custom/static/page" ] $url_parameter=$_Get['route'] “www.domain.com/index.php?route=custom/static/page”,这里$_Get['route']="custom/static/page" ] $url_parameter=$_Get['route']

to

"www.domain.com/page" [here $_Get['route']="page"], “www.domain.com/page”[这里$ _Get ['route'] =“page”],

So now you can mannually add "custom/static/" to the obtained value of $_Get['route']. 所以现在你可以手动将“custom / static /”添加到$_Get['route'].获得的值中$_Get['route']. as $url_parameter="custom/static"+$_Get['route'] //For PHP as $url_parameter="custom/static"+$_Get['route'] //For PHP

Using your mod_rewrite you can fulfill your demands, 使用mod_rewrite可以满足您的需求,

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

But if you need out of box solution using .htaccess then I suggest learning "rewrite-engine" instead of using generating tool 但是如果您需要使用.htaccess的开箱即用解决方案,那么我建议学习“重写引擎”而不是使用生成工具

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM