将 URL 重写为具有多个 APP 的子文件夹

发布于 2024-09-30 10:55:01 字数 1440 浏览 2 评论 0原文

我有多个 CakePHP 项目托管在同一域上,还有一些带有随机文件的随机文件夹,为了组织我在文件夹中分离了应用程序,但当用户访问域时,我有位于 site 文件夹中的“主”应用程序它应该将 URL 重写为 /site,我的问题是随机文件夹,当我尝试访问 domain.com/exist_folder 时,它会将我重定向到 /site。

如果服务器上存在文件/目录,我不想重写。

FTP 树示例

public_html/
 -cakephp (CakePHP Core)/
   - ...
 -site (CakePHP App)/
   - ...
   -.htaccess
   -webroot/
     -.htaccess
 -exist_folder/
   - whateverfiles.ext
 -app1 (CakePHP App)/
   - ...
   -.htaccess
   -webroot/
     -.htaccess
 -folder1/
 -temp/
   -images
   -videos
 -.htaccess

我的 .htaccess

public_html/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule    ^$    site/    [L]
    RewriteRule    (.*) site/$1    [L]
</IfModule>

site/.htaccess 和 app1/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
 </IfModule>

site/webroot/.htaccess 和 app1/webroot/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

I have multiple CakePHP Projects hosted on same domain and some randoms folders with randons files, for organize I separated APPs on folder, but I have the "main" app that are in site folder, when user access domain it should rewrite URL to /site, my problems are with randoms folders, when I try access domain.com/exist_folder it redirect me to /site.

I dont want to rewrite if file/directory exist on server.

Example of FTP Tree

public_html/
 -cakephp (CakePHP Core)/
   - ...
 -site (CakePHP App)/
   - ...
   -.htaccess
   -webroot/
     -.htaccess
 -exist_folder/
   - whateverfiles.ext
 -app1 (CakePHP App)/
   - ...
   -.htaccess
   -webroot/
     -.htaccess
 -folder1/
 -temp/
   -images
   -videos
 -.htaccess

My .htaccess

public_html/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule    ^$    site/    [L]
    RewriteRule    (.*) site/$1    [L]
</IfModule>

site/.htaccess AND app1/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
 </IfModule>

site/webroot/.htaccess AND app1/webroot/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就是爱搞怪 2024-10-07 10:55:01

所以基本上你有一些文件夹你不想通过 Cake 的路由和调度程序。为此,请在 public_html/.htacess 文件中添加以下行:

RewriteRule   ^(exist_folder).* - [NC,L]

这将允许直接访问根目录中的 exit_folder。添加此规则后,可以访问 http://domain.com/exist_folder

如果您正在寻找自动化解决方案(您的台词:如果服务器上存在文件/目录,我不想重写),请创建一个 php 文件,该文件将根据 is_dir() 使用上述 RewriteRule 生成 .htaccess 文件。每当您添加文件夹时,运行此 php 文件,该文件将生成一个 .htaccess 并添加所有例外:)

So basically you have some folders which you don't want to pass through Cake's routing and dispatcher. For this, add the following lines in your public_html/.htacess file:

RewriteRule   ^(exist_folder).* - [NC,L]

This will allow direct access to the exist_folder which is in root directory. Accessing http://domain.com/exist_folder would be possible after adding this rule.

If you are looking for an automated solution (Your lines: I dont want to rewrite if file/directory exist on server), create a php file which will generate a .htaccess file with above mentioned RewriteRule basing on is_dir(). Whenever you add a folder, run this php file which'll generate a .htaccess with all the exceptions added :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文