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
精彩评论