【问题标题】:domain is redirected to suddirectory by mod_rewrite but cakePHP is messing up urls域被 mod_rewrite 重定向到 suddirectory 但 cakePHP 弄乱了 url
【发布时间】:2011-05-24 22:08:21
【问题描述】:

我目前将我的主域从根目录重定向到子目录。正因为如此,每次我使用 cakePHP 编写 URL 或获取当前 URL 时,它都会显示子目录。

例如: 如果我在主页 (http://example.com) 然后使用 cake 的 $this->url 它将返回 /mysubdirectory/

这是我在根目录中使用的 .htaccess 文件(当然已修改为适合我的需要),它重定向到子目录。

# Hostmonster.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subdirectory/index.php [L]

我觉得我需要修改我的 cakePHP 应用程序中的 .htaccess 文件以忽略子目录,但我不确定如何。

【问题讨论】:

    标签: .htaccess cakephp mod-rewrite


    【解决方案1】:

    你添加了吗

    RewriteBase /subdirectory/
    

    在放置 /app 和 /cake 文件夹的目录中的 .htaccess 中?

    【讨论】:

    • 感谢您的回复...我刚刚尝试过,但没有成功。
    • 我将从默认的 .htaccess 开始,下一步更改重写基础,如上所示。我认为没有必要改变其他地方的路径
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2018-03-19
    • 2013-09-07
    • 2013-02-19
    • 2012-05-13
    相关资源
    最近更新 更多