简体   繁体   中英

mod_rewrite for (sub)domains and cakephp's wrong urls

I'm on hosting where I'm rewriting my domains to their folders:

www.domain.com -> domains/domain.com/www

I'm using following htaccess in document root

Options +FollowSymLinks +Indexes
RewriteEngine On 

# www->non-www
RewriteCond %{HTTP_HOST} ^www\.([a-z0-9-.]+)$ [NC]
RewriteRule (.*) http://%1/$1 [R=301,QSA,L]

# www
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.([a-z]+)$ [NC]
RewriteCond $0 !^domains/
RewriteRule (.*) /domains/%1.%2/www/$1 [L]

#non-www
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.([a-z0-9-]+)\.([a-z]+)$ [NC]
RewriteCond $0 !^domains/
RewriteRule (.*) /domains/%2.%3/%1/$1 [L]

Everything works but cake creates wrong (ugly) urls. It works but...

cakephp 2.0 running on domain.com contains $this->Html->link("/controller");. It creates link to /domains/domain.com/www/controller instead of /controller.

Hy,

Use routes.php from app/config It's cake htaccess. If you use htaccess and routes.php you rewrite your link twice i think...

For example:

    Router::connect('/', array('controller' => 'your_controller', 'action' => 'your_actiom'));

You can configure your routes like an htaccess The path for this route:

    http://your_domain.com/controller/action

Also you can add params in a route (for editing or something else)

Here you have all routes manual

If you have another question, go ahead!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM