简体   繁体   中英

How do I capture the url-path to do a htaccess redirect?

What I'm looking to do is take http://mydomain.com/1a3b5c and redirect it to http://mydomain.com/page?id=1a3b5c and if possible still keep mydomain.com/1a3b5c in the browser's address bar. If this isn't possible, then the simple redirect is fine.

What you are interested in is typically called 'Clean URLs' and is done like this:

RewriteRule ^([a-zA-Z0-9]+)$ /page?id=$1 [L]

This is assuming you are using Apache as your web server and have mod_rewrite enabled.

It will preserve the original visible URI.

This may need to be modified based on your precise needs, but this should give you the general direction of where to go.

If your webserver is apache you want to use Mod Rewrite. Something like this I think

RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/page\?
RewriteRule (.*) page=$1

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