BTS*_*TSM 6 .htaccess mod-rewrite redirect url-rewriting server
我有两个网页。我想将这两个页面部署在一个域上。当我调用根URL时,我想加载index.html
根目录中的,而对于其他URL,我想加载目录index1.html
中的/app
。
这是目录结构。
www.example.com/index.html
www.example.com/app/index1.html
Run Code Online (Sandbox Code Playgroud)
例如:请求www.example.com
加载时index.html
用于www.example.com/login
装载/app/index1.html
用于www.example.com/signup
装载/app/index1.html
这是我尝试过的。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /app/index1.html [R=301,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
www.example.com/signup
当我请求时,这会进行重定向www.example.com/app/index1.html
。
但我想加载app/index1.html
而不重定向。请帮我。
对于您显示的示例,请尝试遵循 .htaccess 规则。在测试您的网址之前,请确保以下事项:
.htaccess
文件index.html
和app
文件夹位于同一root
文件夹中。index1.html
内有文件/app
。
RewriteEngine ON
##Rule from OP's attempt to block direct access of index.html file.
RewriteRule ^index\.html$ - [NC,L]
##Rule to handle only url www.example.com here.
RewriteRule ^/?$ /index.html [QSA,NC,L]
##Rules to handle rest of the cases here..
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ /app/index1.html [QSA,NC,L]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1182 次 |
最近记录: |