【问题标题】:RewriteBase in .htacces when you have multiple directories under the root当根目录下有多个目录时,.htaccess 中的 RewriteBase
【发布时间】:2019-03-23 03:03:15
【问题描述】:

在我的根目录中,我有太多不同项目的子文件夹。目前我正在使用 cakephp,我必须设置 .htaccess 文件才能访问 index.php。

这是我创建的不同 .htaccess 文件:

在lampp的htdocs中:

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

carte_drin cakephp 项目文件夹中:

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

app文件夹中

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

webroot 文件夹中:

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

我的问题是当我尝试访问另一个项目时,我被定向到 carte_drin 项目。我相信 htdocs 中 .htaccess 文件的重写规则会导致问题。

我需要一种方法在根目录的每个项目文件夹中创建 .htaccess 点。

【问题讨论】:

  • 您应该为您的个人项目设置适当的虚拟主机......
  • 你能再解释一下吗?
  • 现在您正在浏览器中通过http://localhost/project1/http://localhost/project-xy/ 等方式访问它,对吧?相反,您应该进行设置,以便每个项目在其自己的域名下可用,该域的文档根目录直接指向相应的项目文件夹。然后,您应该能够使用这些框架附带的“默认”重写,而无需进行手动调整。 dasunhegoda.com/what-how-to-apache-virtual-host/444

标签: php .htaccess mod-rewrite cakephp


【解决方案1】:

设置适当的虚拟主机。在您的 apache conf 文件夹中,首先打开主 conf 并取消注释包括 httpd-vhosts.conf 的行。在额外的子目录中,您会找到httpd-vhosts.conf。打开它,并为每个站点添加一个主机配置。您应该能够删除 .htaccess 文件,将任何这些信息放入 vhost 配置中。这里我设置了dev.example.com,它位于/var/www/devsite,index.php 位于/var/www/devsite/public/index.php

<VirtualHost *:80>
    DocumentRoot "/var/www/devsite/public"
    ServerName dev.example.com
    ServerAdmin delboy1978uk@gmail.com
    ErrorLog "/var/www/devsite/logs/error_log"
    SetEnv APPLICATION_ENV development
    <Directory "/var/www/devsite">
        DirectoryIndex index.php
        FallbackResource /index.php
        Options -Indexes +FollowSymLinks
        AllowOverride all
        Require all granted
    </Directory>
    BrowserMatch ".*MSIE.*" nokeepalive downgrade-1.0 force-response-1.0
</VirtualHost>

完成后,在 Linux 或 Mac 笔记本电脑上编辑 /etc/hosts,或在 Windows 上编辑 c:\windows\system32\drivers\etc\hosts,添加以下行:

127.0.0.1 dev.example.com

然后重新启动您的 apache,启动您的浏览器,然后前往 dev.example.com。您的网站现已在虚拟主机上启动并运行!

【讨论】:

  • 我是新手,我刚刚开始学习这些东西。当我打开 httpd-vhosts.conf 时,我发现了两个 ... 块我必须同时更改它们吗?
  • 这些只是示例,您可以将它们注释掉或删除它们。试试我给你的那个!
  • 我正在使用远程服务器和 /etc/hosts 在哪里可以找到?
  • 这是 linux 上的完整路径!
  • 我在 hosts 文件中找到了这两行:127.0.0.1 localhost vps210798.ovh.net #51.254.205.243 vps210798.ovh.net vps210798。我在我的 url 中使用 51.254.205.243 来访问我的项目。我是否必须使用它而不是其他 IP 地址,并且 httpd-vhosts.conf 文件的更改行也在 xampp 的 apache2 的 /etc 中。然而 /opt/lampp/etc 中没有主机
猜你喜欢
  • 2023-03-16
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-02
  • 1970-01-01
  • 2014-11-24
相关资源
最近更新 更多