.htaccess 为什么重写不能屏蔽URL?

gorkyyrv  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(112)

我有一个页面,其URL如下:

https://example.net:9000/something

我希望能够从这里访问它https://example.net/mysite
并屏蔽URL,以便在最后一个/
我这样试过:
重写规则^:9000/某些内容/?$ /mysite/
但是没有用,为什么?
此外,我在htaccess上还有一些其他规则必须保持不变:

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /public/404.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]           <---everything up to this point has to stay the same

RewriteRule ^:9000/something/?$ /mysite/
</IfModule>
  • 谢谢-谢谢
zpgglvta

zpgglvta1#

https:/example.net/https://example.net:9000有两个独立的http主机,它们之间没有任何关系,所以实际上需要https:/example.net/的服务器来代理要转发到https://example.net:9000的请求。
假设https:/example.net/由apache http服务器提供服务(取决于您提出问题的方式),那么使用apache代理模块应该可以实现这一点,可以直接使用:

ProxyRequests off
ProxyPass /mysite/ https://example.com:9000/something/
ProxyPassReverse /mysite/ https://example.com:9000/something/
  • (是的,如果在中心服务器配置中实现了ProxyRequests off,则确实是ProxyRequests off,而不是on。如果您仅有权访问 dsitributed 配置文件(.“htaccess”),则保留该行)*

...或通过重写模块:

RewriteEngine on
RewriteRule ^/?mysite/(.*)$ https://example.com:9000/something/$1 [P]

显然,代理模块和proxy_http模块必须加载到http服务器中。该规则必须在为https:/example.net/服务的http主机的配置中实现。如果您没有访问权限,可以在该主机的DOCUMENT_ROOT中的 distributed 配置文件(通常称为.“htaccess”)中实现。

相关问题