htaccess 子域重定向与最后一个 url 参数 [英] htaccess subdomain redirct with last url parameter

查看:26
本文介绍了htaccess 子域重定向与最后一个 url 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个 .htaccess 文件,用于将我的子域和 URL 的最后一个变量重定向到新位置.这是我想要做的:

I want to write a .htaccess file for redirecting my subdomains and URL's last variable to a new location. Here is what I want to do:

http(s)://abc.example.com/books

http(s)://abc.example.com/books

我希望我的内部 URL 是这样的:

I want my internal URL to be like:

http://example.com/?name=abc&type=books

我已经让子域重定向工作了,但我无法在 URL 的最后一部分使用变量来做子域.

I have already gotten the subdomain redirect to work but I am not able to do subdomain with variable in last part of URL.

我怎样才能做到这一点?

How can I accomplish this?

推荐答案

这应该可以满足您的需求:

This should do what you want:

RewriteCond %{HTTP_HOST} ^(.+).example.com
RewriteRule ^(.*)% http://example.com/?name=%1&type=$1 [R,L]

%1"表示使用上述 RewriteCond 中的第一个捕获组.

The "%1" means use the first capture group from the RewriteCond above.

这篇关于htaccess 子域重定向与最后一个 url 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆