在GoDaddy上的Cakephp htaccess mod_rewrite

时间:2010-07-07 00:42:00

标签: .htaccess cakephp mod-rewrite

我有一个godaddy托管帐户,并有一些问题 路由。这些文件位于默认 / html 文件夹下的 / cakephp 下。 完整的网址仍然显示而不是所需的

 www[dot]domain[dot]org

请帮忙。

当前设置

/cakephp/.htaccess

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

/cakephp/app/.htaccess

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

/cakephp/app/webroot/.htaccess

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

1 个答案:

答案 0 :(得分:3)

如果我理解正确,您可以通过以下方式访问您的申请:

# http://example.com/cakephp/*   # normally served from html/cakephp/

...相反,您希望网址显示如下:

# http://example.com/*           # normally served from html/

最简单的选择是将cakephp目录中的所有文件和文件夹向上移动一级,因为它的目的是“开箱即用”,所以目录结构是这样的:

# html/.htaccess               <- this file would then ...
# html/app
# html/app/.htaccess
# html/app/webroot             <- ... rewrite requests to here
# html/app/webroot/.htaccess
# html/cake

如果您希望保留cakephp包含目录,则需要将自己的.htaccess文件添加到html/目录,以告知Apache您的意图。结构将是这样的:

# html/.htaccess               <- your .htaccess file goes here
# html/cakephp/.htaccess       <- it should look similar to this one
# html/cakephp/app
# html/cakephp/app/.htaccess
# html/cakephp/app/webroot     <- you need to rewrite requests to here
# html/cakephp/app/webroot/.htaccess
# html/cakephp/cake

其内容可以从第一个CakePHP .htaccess文件中复制(如上所述)并稍作修改以产生您所追求的结果。像这样:

RewriteEngine on
RewriteRule ^$   cakephp/app/webroot/   [L] # rewrites requests to example.com/
RewriteRule (.*) cakephp/app/webroot/$1 [L] # rewrites requests to example.com/*