问题
There is /localhost/domains/localhost/myCakephpApp on web server. I can't do anything with folder structure, but I can edit .htaccess in /localhost/, which now simplified looks like this:
RewriteRule (.*) /domains/localhost/$1 [L]
My website in localhost/domains/localhost/myCakephpApp has standard cake .htaccess file:
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
It is nice that http://localhost/whatever/ works, but all links in cakephp (done with html helper) are pointing to http://localhost/domains/localhost/whatever/ and it is accessible.
What should I do to make the website running only on http://localhost/ and not on http://localhost/domains/localhost/?
EDIT:
Okay, I have modified the .htaccess in root (http://localhost/):
RewriteRule ^$ /domains/localhost/app/webroot/ [L]
RewriteRule (.*) /domains/localhost/app/webroot/$1 [L]
and deleted one in http://localhost/domains/localhost/ which means that the web is only accessible from http://localhost, but links are still pointing at http://localhost/domains/localhost/whatever (e404)
Is there something in cake's routing like "base url"? I have searched a lot, but nothing worked.
回答1:
The problem is that CakePHP uses the original uri from the server to resolve the action, not the rewritten one!
Try this "hack" in bootstrap.php:
Configure::write('App.base', '/');
$_SERVER['REQUEST_URI'] = preg_replace('|/domains/localhost|', '', $_SERVER['REQUEST_URI']);
回答2:
You could add a redirecting route:
Router::redirect('/domains/myDomainName.com/*', '/');
If you want to completely disable the route you can redirect to a 404 page. Something like that should work:
Router::redirect('/domains/myDomainName.com/*', array('controller'=>'pages', 'action'=>'error-404'), array('status' => '404'));
plus adding a 404-page in /View/Pages/error-404.ctp.
来源:https://stackoverflow.com/questions/10404892/htaccess-is-not-working-by-my-desires-with-cakephp