I have my cakephp .htaccess files set up as in the cookbook and everything is working fine.
My web site currently has multiple domains, all of which point to the same site (e.g. www.site.com, www.site.co.uk). I'd like to set up a rule so that requests to www.site.co.uk/page are permanently redirected to www.site.com/page, etc.
I'm having trouble getting both rules to work together. Can anyone help me out?
EDITED TO INCLUDE FURTHER DETAILS:
Here is the .htaccess file in my web root:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
# Force domain to be www.site.com
RewriteCond %{HTTP_HOST} !^www\.site\.com$
RewriteRule ^(.*)$ http://www.site.com/$1 [R=permanent,NC]
# For CakePHP
RewriteCond %{HTTP_HOST} ^www\.site\.com$
RewriteRule ^(.*)$ app/webroot/$1 [NC]
</IfModule>
I also have a separate CakePHP app in a subdirectory: tbgroup. Here is the .htaccess file (tbgroup/.htaccess):
<IfModule mod_rewrite.c>
RewriteEngine on
# For CakePHP
RewriteRule ^(.*)$ app/webroot/$1 [NC]
</IfModule>
Everything works as fine: www.site.co.uk is redirected to www.site.com, www.site.co.uk/page is redirected to www.site.com/page. CakePHP works fine. The only problem is www.site.co.uk/tbgroup is not redirected to www.site.com/tbgroup - it remains as www.site.co.uk/tbgroup (and CakePHP works fine).
Try it out on the live site if you like (www.site.com or www.site.co.uk).
I believe that you've pointed out the answer in the permanent redirection link in your question.
It's really not related to cakephp. It's just mod-rewrite issue. You have yo put this code in your .htaccess file (under /app/webroot)
rewritecond %{http_host} ^(www.)?site.co.uk [nc]
rewriterule ^(.*)$ http://site.com/$1 [r=301,nc]
Related
Litespeed obeys .htaccess rules but I cannot seem to get it to work for what should be a basic problem for which I cannot find a solution online. I want to redirect from this with everything in the sub-directory:
https://example.com/mail/
to
https://mail.example.com/
What I have tried so far that does NOT work:
SETUP 1
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^/mail$
RewriteRule ^(.*)$ https://mail.example.com/$1 [R=301,L]
SETUP 2
RewriteRule ^mail/(.*)$ https://mail.example.com/$1 [R=301,NC,L]
SETUP 3
Redirect 301 /mail/ https://mail.example.com/
I have also tried another 5 things that don't work. The mail.example.com server is different from the one example.com/mail/ is sitting on.
EDIT TO ANSWER COMMENTS:
I have put the .htaccess file both in the root directory and the mail sub-directory but it does not redirect. By not working, I mean that the page just goes back to the original URL (example.com/mail/) instead of redirecting as expected.
Your setup #1 is almost OK. The reason why it failed is because the RewriteCond %{HTTP_HOST} ^/mail$ is not matched. You need to change the pattern ^/mail$ to (www\.)?example\.com$ where example.com is your main domain and place the code in /mail/.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^(.*)/?$ https://mail.example.com/$1 [R=301,L]
We have a WordPress site/single app which serves two domain names: example.com and example.es.
In our .htaccess file we have currently have the following rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.es
RewriteRule ^(.*)$ http://www.exmaple.es/$1 [R=permanent,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
We also need to redirect everything from example.com/es/... to example.es/.... I have tried multiple examples that I could find, but none of them worked (ended up in 500 server error and empty log), here are a few of them:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) http://www.example.es/%1 [R=302,NC]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com/es [NC]
RewriteRule ^(.*)$ http://www.example.es/$1 [R=301,NC,L]
All of the new rules were placed inside the <IfModule mod_rewrite.c>
Any help or guidance is much appreciated.
#Domas Hi Domas, the process in your case is to update you site installing some important extension about the domain change.
Changing the preferred domain name alias WordPress uses
If your WordPress site has a domain name alias pointing to it, and you want WordPress to prefer the alias domain name in links that it generates, you can update the domain name in the WordPress dashboard:
Click Settings.
Change the WordPress Address (URL) to the new URL that you want to use.
Change the Site Address (URL) to the same value.
Click Save Changes.
You need WP Super Cache, this extension help you to update automatically the .htaccess and change all the needs as you did on you configuration site.
First install the extension https://support.tigertech.net/move-wordpress#updating-htaccess-wp-jmp
Also if you don't need any extension and you want to do by the hand just redirect like this example as needs :
#the simple redirection
Redirect 301 /es http://www.example.es/
#Redirect from old domain with subdirectory to new domain
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) http://www.example.es%{REQUEST_URI} [R=302,NC]
It depend of you needs i prefer the last one. Regards
I am pulling my hair out here.
I have created a landing page which is http://www.pps-supplements.com/samples
it works and you can access it fine - no problems.
If you type in the address bar:
pps-supplements.com/samples
it takes you to the home page which is not good and causing me to have a headache.
My website is working well for non www to www on home page and categories but not on cms pages.
I have read a few posts on here and tried their solutions which is to edit the htaccess file but it hasn't fixed it.
Does anyone have any ideas how I can resolve this issue??
Pretty please!
You could try this in your .htaccess file....
Be sure to add it above any other rewrite rules or conditions you may already have in your htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.pps-supplements\.com [NC]
Rewriterule (.*) http://www.pps-supplements.com/$1 [R=301]
</IfModule>
This will redirect any domain that is not www.pps-supplements.com to the version with www's
Also very handy for using when pointing multiple domains at a site.
Also, be sure that the webserver is set-up to receive the non www version, as in that it is listening for that version, as well as for the version with www's.
For anyone else looking at the accepted answer and running into issues with it not working you may have other Rewrites in place that need to be stopped from executing.
You can stop further execution by including the "L" param.
Example:
Rewritecond %{HTTP_HOST} !^www\.domain\.com [NC]
Rewriterule (.*) http://www.domain.com/$1 [R=301,L]
I wanted to redirect from example.com/category/ to www.example.com/category/
and I found solutions:
turn off Auto-redirect to Base URL in backend
and use this code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>
For Magento Multistore-Setups:
Rewritecond %{HTTP_HOST} ^example\.com [NC]
Rewriterule (.*) http://www.example.com/$1 [R=301,L]
how to redirect www.sub.domain.com to sub.domain.com?
other info:
right now sub.domain.com works, www.sub.domain.com is 'server not
found'.
im using drupal 6. I dont want to add an A record because the caching module i use (Boost) will cache a version of the site with www and without www, effectively doubling the cache size. <-- Not really sure about that but that's the case with my site at its previous host. In any case this is probably just a simple htaccess issue.
Doesn't this helps, inside .htaccess file?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
Also: https://drupal.stackexchange.com/questions/50552/how-to-keep-domain-consistency-with-or-without-www/50553#50553
I have a site done with cakePHP and I access to the sites there like:
http://example.com/site1
Which is converted to:
http://example.com/app/webroot/site1
As I've searched and seen here or searching here in stack-overflow this is the normal behaviour but I'd like that the user actually doesn't see the app/webroot bit.
Is that possible?
Here is my current .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.example.com/$1 [R=301,NE,L]
# CakePHP part
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Thank you
If you followed all the instructions to install CakePHP, the URL without /app/webroot should work too. If it is not working, re-download all the .htaccess files from the CakePHP repo. There are three files.
To get rid of the /app/webroot, i.e. never see that path on any URL, you may edit or create a VirtualHost with a DocumentRoot pointing to the absolute path of your webroot.
Something like this:
<VirtualHost 127.0.0.2:80>
DocumentRoot /absolute/path-to/app/webroot
</VirtualHost>
This is not possible if you are on a shared server. If you are on a managed VPS or dedicated server, you need to contact your hosting. If it is unmanaged, you can do it yourself.