【问题标题】:How can I bypass the .htaccess in a parent directory?如何绕过父目录中的 .htaccess?
【发布时间】:2014-06-15 21:57:11
【问题描述】:

我的问题与:Zend Framework 2 without Vhost configuration 相同,但解决方案没有解决我的问题。

我得到一个自定义的 404 页面。

我的项目位于子目录中,我相信父目录中的 .htaccess 正在阻止它工作。

注意:我无法删除那个,因为那里正在运行另一个项目

htdocs/.htaccess:

Options -Indexes
Options +SymLinksIfOwnerMatch
RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

RewriteRule ^transcripts/$ https://spreadsheets.google.com/a/ci4tcm.com/ccc?    key=0AodnCB9Mr1K1dFFmbGhOc3V4RjBvNzZxSE9EZ1dtSnc&hl=en#gid=0 [R,NC]

# ErrorDocument 404 /pages/404.html
# ErrorDocument 500 /pages/404.html
# ErrorDocument 403 /pages/404.html

# RewriteRule ^css(/)?$ / [R]



# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)$ /download/$1/$2/ [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)/$ /download.php?test=$2&fol=$1

RewriteRule ^download/([A-Za-z0-9.]*)$ /download/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)/([A-Za-z0-9\+.-\s]*)$ /download.php?folder=$1&file=$2 [L]

RewriteRule ^download/([A-Za-z0-9.]*)$ /posters/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)$ /images/wellbeing_posters/pdfs/$1 [L]

AddHandler server-parsed html

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.another-domain\.com\/$1" [R=301,L]

# A bunch of redirect 303's here

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

htdocs/booking/ (其他问题的解决方案)。

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} = ""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

所以我的问题是,当用户想要使用 Zend 应用程序进入物理子目录时,我如何绕过父目录 .htaccess 规则?

【问题讨论】:

  • 另一个问题的链接不正确。它指向“询问”页面。
  • 是什么不工作?父文件夹 .htaccess 规则只是在 URL 中强制执行 www,它们不会对您的 ZF 项目中的规则造成任何问题。
  • @Ruben 我更新了链接
  • @TimFountain 我不允许配置虚拟目录。链接中的答案对我不起作用,所以我认为可能是另一个 htaccess 导致它。尝试访问我的 ZF 应用程序时,我收到了一个自定义的 404 未找到页面。
  • ZF 404 页面?如果是这样,则更有可能是路由问题。

标签: .htaccess mod-rewrite zend-framework2 virtualhost


【解决方案1】:

您编辑的问题在父文件夹中的.htaccess 中添加了一大堆东西,这会有所改变。假设您能够编辑该 htaccess,最简单的做法是将 ZF 规则移入其中。只需更改任何包含public 的行并在其前面添加c-booking。例如,最后一行如下所示:

RewriteRule ^c-booking/public/.*$ /c-booking/public/index.php [NC,L]

另请注意,这是一种不太安全的应用托管方式。如果您有任何非 PHP 配置文件、缓存文件等(通常位于 Web 根目录之外的内容),请确保它们无法通过浏览器查看。

【讨论】:

  • 感谢您的回答。在我将它们移动到另一个 htaccess 后更改这些行,或者如果我更改行我不需要移动它们?如何从浏览器中隐藏这些文件?如果没有必要,我宁愿不碰那个 htdocs。
  • 如果要移动行,则需要对其进行编辑,以使路径正确。
  • 有没有不需要移动线条的解决方案?
猜你喜欢
  • 2019-10-03
  • 1970-01-01
  • 1970-01-01
  • 2012-07-15
  • 2023-03-24
  • 1970-01-01
  • 2014-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多