繁体   English   中英

除某些目录外,将根目录重写为子文件夹 (.htaccess)

[英]Rewrite root to subfolder (.htaccess) except some directories

我有以下文件夹结构:

  • app/(包含 index.php、js/、public/)
  • v1/
  • .htaccess

对 v1 的请求应该照常工作 所有其他请求都应该转到 /app 而不更改 url

www.xxx.com/           (displays: app/index.php)
www.xxx.com/v1         (displays: v1/index.php)
www.xxx.com/js/xxx.js  (displays: app/js/xxx.js)

这可能吗?

基本上,静态文件夹: v1、app/js(不带应用程序)、app/public(不带应用程序)

所有其他请求都转到app/index.php而不更改 url。

要重写请求/root/subfoldwr您可以使用下面的规则在你/.htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /app/index.php  [L]

这会将除现有文件/目录之外的所有内容从/root文件重写到/app/index.php

您可以在站点根目录 .htaccess 中使用此规则:

RewriteEngine On

# landing page
RewriteRule ^/?$ app/index.php [L]

# if v1/file exists then use it
RewriteCond %{DOCUMENT_ROOT}/v1/$1 -f
RewriteRule .+ v1/$0 [L]

# if app/public/file exists then use it
RewriteCond %{DOCUMENT_ROOT}/app/public/$1 -f
RewriteRule .+ app/public/$0 [L]

# if app/js/file exists then use it
RewriteCond %{DOCUMENT_ROOT}/app/js/$1 -f
RewriteRule .+ app/js/$0 [L]

# if not a file, not a dir and not starting with v1    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^v1/ app/index.php [L,NC]

暂无
暂无

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

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