【发布时间】:2020-11-18 06:33:40
【问题描述】:
我的文件夹结构是这样的:www.testlink.com/angular/dist/my-app。
输入此链接时,我必须访问此文件夹:www.testlink.com/angular。
如何使用 htaccess?
【问题讨论】:
-
请在您的问题中分享您为解决此问题而编写的 htacces 文件规则。
我的文件夹结构是这样的:www.testlink.com/angular/dist/my-app。
输入此链接时,我必须访问此文件夹:www.testlink.com/angular。
如何使用 htaccess?
【问题讨论】:
如果你使用子域会更好
htaccess 配置
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
将基本网址添加到 index.html
<base href="http://subdomain.testlink.com/">
配置阿帕奇
<VirtualHost *:80>
ServerName www.subdomain.example.com
ServerAdmin webmaster@localhost
DocumentRoot /path/of/your/directory
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
【讨论】:
这可能是您正在寻找的,外部重定向与内部重写的组合:
RewriteEngine on
RewriteRule ^/?angular/dist/my-app(/.*) /angular$1 [QSA,R=301,END]
RewriteRule ^/?angular(/.*) /angular/dist/my-app$1 [QSA,END]
显然需要在 http 服务器内启用重写模块,并且必须在 http 服务器内的该位置启用分布式配置文件(“.htaccess”)的解释。
【讨论】:
RewriteEngine On # Don't rewrite files RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] # If the ALPHA_USER cookie is set, serve the uncompressed files RewriteCond %{HTTP_COOKIE} ALPHA_USER [NC] RewriteRule ^ index.html [L] # Rewrite everything RewriteRule ^ dist/my-app/index.html [L]