如何使用htaccess在尾部斜杠后将所有子域重定向到另一个带有参数的子域? [英] how to redirect all subdomains to another with parameter after the trailing slash using htaccess?

查看:50
本文介绍了如何使用htaccess在尾部斜杠后将所有子域重定向到另一个带有参数的子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在通配符中使用任何内容,它会将我重定向到 example.com/shop.但我想要的是当有人使用 anything.example.com/code 时,他会重定向到 example.com/shop/code.当前设置将我重定向到 example.com/code/shop,如果我在我的例子中它的 code 尾部斜杠后使用任何东西.

If I use anything in wildcard it's redirecting me to example.com/shop. But what I want is when someone uses anything.example.com/code he redirects to example.com/shop/code. The current setting is redirecting me to example.com/code/shop if I use anything after the trailing slash in my case its code.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^[^.]+\.(example\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI}/shop [R=301,L,NE]

推荐答案

您似乎只需要反转 substitution 中的 %{REQUEST_URI}/shop 部分字符串... (?)

You would seem to just need to reverse the %{REQUEST_URI}/shop part in the substitution string... (?)

例如:

RewriteCond %{HTTP_HOST} ^[^.]+\.(example\.com)$ [NC]
RewriteRule ^ http://%1/shop%{REQUEST_URI} [R=301,L,NE]

REQUEST_URI 服务器变量包含用户请求的完整 URL 路径(仅),包括斜杠前缀.

The REQUEST_URI server variable contains the full URL-path (only) that the user requested, including the slash prefix.

您需要在测试前清除浏览器缓存.(最好先测试 302 临时重定向以避免缓存问题.)

You will need to clear your browser cache before testing. (Preferably test first with 302 temporary redirects to avoid caching issues.)

这篇关于如何使用htaccess在尾部斜杠后将所有子域重定向到另一个带有参数的子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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