简体   繁体   English

.htaccess重定向到外部URL,但使用mod_rewrite

[英].htaccess redirect to external url but with mod_rewrite

I have two webspaces, one domain. 我有两个网站空间,一个域。 One webspace contains ~ 5 TB Audiofiles & Images, and one webspace is for the script. 一个网站空间包含约5 TB音频文件和图像,而一个网站空间用于脚本。

My problem: 我的问题:

Take for eg my webspace url are domain1.tld & domain2.tld 以我的网站空间网址为domain1.tld和domain2.tld

On domain2.tld are all(!) files and and other things. 在domain2.tld上是all(!)文件和其他东西。 On domain1.tld i uploaded only the php files. 在domain1.tld上,我仅上传了php文件。

The problem is that if i want to see a video, which is for eg on domain2.tld/files/video01.mp4 and the link shows domain1.tld/files/video01.mp4 - how can i change this if this file not exist to go to domain? 问题是,如果我想观看视频,例如,在domain2.tld / files / video01.mp4上,链接显示domain1.tld / files / video01.mp4-如果此文件不存在,如何更改此视频去域名?

I saw here a similar question. 我在这里看到了类似的问题。

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^subdirectory/?$ http://newurl.com [L,R=301,NC]

But this have 1 problem: 但这有1个问题:

  1. If i go to http://domain1.tld/%FILE% and if this not exist -> it should be located to http://domain2.tld/%FILE% 如果我去http://domain1.tld/%FILE% ,如果不存在->它应该位于http://domain2.tld/%FILE%

And is it possible to work with mod_rewrite? 并且可以使用mod_rewrite吗?

So i mean, if domain1.tld/%FILE% dont exist, it should be the same url but it should be the access of domain2.tld/%FILE% 所以我的意思是,如果domain1.tld /%FILE%不存在,它应该是相同的url,但它应该是domain2.tld /%FILE%的访问权限

Thanks! 谢谢!

Try that: 试试看:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ http://domain2.tld/$1 [L,R=302,NC]

It means: if file or directory or symlink not found here, do redirect to domain2.tld . 这意味着:如果在这里找不到文件,目录或符号链接,请重定向到domain2.tld。

(It's 302 because testing new rewrite rules with permanent redirect is dangerous ) (这是302,因为使用永久重定向测试新的重写规则很危险)

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

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