简体   繁体   中英

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.

I don't know regex so I tried http://www.generateit.net/mod-rewrite/ , but it only generates

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? and doesnt pass variable, any help is appreciated.

Do you know the concept of using mod-rewrite?

In your question you have mentioned to use mod-rewrite to redirect

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

to

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

So now you can mannually add "custom/static/" to the obtained value of $_Get['route']. as $url_parameter="custom/static"+$_Get['route'] //For PHP

Using your mod_rewrite you can fulfill your demands,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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