Mod 重写假子域?

发布于 2024-08-24 22:51:13 字数 561 浏览 4 评论 0原文

我确实尝试了很多方法,但没有成功。 我想要一个 .Htaccess 代码来执行以下操作:

我想重命名它: http://www.mydomain.com /媒体 --> http://media.mydomain.com

因此,通过示例而不是调用此: http://www.mydomain.com/media/XXX/picture.jpg 我会打电话:http://media.mydomain.com/XXX/picture.jpg

谢谢

I really tried tons of methods but i'm not successful.
I want a .Htaccess code to do the following :

I want to rename this : http://www.mydomain.com/media --> http://media.mydomain.com

So, By example instead of calling this : http://www.mydomain.com/media/XXX/picture.jpg
i will call : http://media.mydomain.com/XXX/picture.jpg

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒中人 2024-08-31 22:51:14

它会是这样的:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.mydomain\.com$
RewriteRule (.*) http://www.mydomain.com%1$1 [L,R=301]

It's gonna be like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.mydomain\.com$
RewriteRule (.*) http://www.mydomain.com%1$1 [L,R=301]
一页 2024-08-31 22:51:14

确保 rewrite_module 已加载,例如;

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

然后添加以下内容(到您的 .htaccess):

RewriteEngine on
RewriteCond %{HTTP_HOST} www.mydomain.com
RewriteRule ^/([^/]*)(.*) http://$1.mydomain.com$2 [L,R]

Cond 仅匹配 www.mydomain.com。然后,规则将使用第一个“/”(将包含在 $2 中)将 URL 分成 2 个,重写并重定向。

Make sure rewrite_module is loaded, something like;

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

Then add the following (to your .htaccess):

RewriteEngine on
RewriteCond %{HTTP_HOST} www.mydomain.com
RewriteRule ^/([^/]*)(.*) http://$1.mydomain.com$2 [L,R]

The Cond will only match www.mydomain.com. The Rule then will split the URL into 2 using the first '/' (which will be included in $2), rewrite and redirect.

瑕疵 2024-08-31 22:51:14

如果您想要相反的(请参阅罗杰的评论)并且不重定向用户

RewriteEngine on
RewriteCond   %{HTTP_HOST}                 !^www\.mydomain\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^([^.]+)\.mydomain\.com(.*)  http://www.mydomain.com/$1$2 [L]

另外,请参阅此处: http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

If you want the opposite (see Roger's comment) and without redirecting the user

RewriteEngine on
RewriteCond   %{HTTP_HOST}                 !^www\.mydomain\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^([^.]+)\.mydomain\.com(.*)  http://www.mydomain.com/$1$2 [L]

Also, see here: http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文