简体   繁体   English

如何捕获 url 路径以进行 htaccess 重定向?

[英]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.我要做的是采取http://mydomain.com/1a3b5c并将其重定向到http://mydomain.com/page?id=1a3b5c并且如果可能的话仍然保留mydomain.com/1a3b5c在浏览器的地址栏中. 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:您感兴趣的通常称为“干净的 URL”,并且是这样完成的:

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.这是假设您使用 Apache 作为 web 服务器并启用了 mod_rewrite。

It will preserve the original visible URI.它将保留原始可见 URI。

This may need to be modified based on your precise needs, but this should give you the general direction of where to go.这可能需要根据您的精确需求进行修改,但这应该为您提供 go 的大致方向。

If your webserver is apache you want to use Mod Rewrite.如果您的网络服务器是 apache 您想使用 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

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

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