Drupal URL change, rewrite goes to static - .htaccess

Setup on media temple, second domain name, same server.
Website duplicated from domainA.com, to domainB.com, under the vhosts. Changed drupal's settings.php to reflect the new domain. When checking under the admin settings, the default front page is listed under the domainB.com URL. So that checks out okay.
Navigate to domainB.com and it resolves as domainA.com's name.
Both domainA & domainB are loading from domainB's folder. This assumption is made because I only changed settings.php in domainB, not domainA, and they are both displaying the data for domainB.
The issue is the address bar is displaying domainA's name.
domainB's htaccess file has:
# enforce https
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domainB.com/$1 [R,L]
# redirect www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domainB\.com$ [NC]
RewriteRule ^(.*)$ https://domainB.com/$1 [L,R=301]
# drupal subdirectory
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/$1 [L]
RewriteRule ^$ drupal/ [L]
# disallow indexes
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
php_flag log_errors on
php_value error_reporting 32767
php_value error_log "/var/www/vhosts/domainB.com/logs/php_error.log"
Goals:
1) domainB is identical in operation to domainA, except for domainB's name displaying in the navigation bar and internal links.
2) domainA points to a static page.

Related

Correctly setting up redirects on Codeigniter using Openserver

I downloaded the Openserver, added the mySite folder to the domains folder. Now installed codeigniter there. When i visit mySite/public/index.php in the browser, the Codeigniter's Home page opens, everything is fine. Now when I do redirect()->to('new/link') it redirects me to http://localhost' instead of mySite/public/index.php/new/link :8080/index.php/new/link and the error Unable to access the site. The localhost site does not allow a connection. CI's routes are set for this page: changing the url to http://mySite/public/index.php/new/link will display the page i am looking for.
For verification, I deduced these values ​​with the results obtained:
var_dump(site_url()); result: string(31) "http://localhost:8080/index.php"
var_dump($_SERVER['SERVER_NAME']); result: string(5) "mySite"
var_dump($_SERVER['REMOTE_ADDR']); result: string(9) "127.0.0.1"
How can I set up the correct redirect? So that when you type mySite it will display the base page, and when you redirect to mySite/new/link, this page will be displayed?
What could be causing this? Does the Windows host substitute localhost instead of mySite, or is something wrong in the .htaccess files, or are the openserver settings set this way?
In the Openserver settings: On the Server tab, Server IP address: 127.0.0.1, Root folder of domains:domains is set. The Aliases tab is empty, if you want to clarify something else, ask.
Hosts file from C:\Windows\System32\drivers\etc:
# Start Open Server 43db4a8d240df3094967da14cf2a4b9c_hosts
127.0.0.1 localhost
127.0.0.1 mySite
.htaccess file in public folder:
Options All -Indexes
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
ServerSignature Off

htaccess serve page from another subdomain silently only when page is not found

My main pages are at "main.mysite.com".
Customer access site by "customer.mysite.com" which contains only a subset of the main pages.
When customer request page "customer.mysite.com/data.php", I want to check first if the file is in "customer.mysite.com" subdomain, if yes, then serve that page, if not, then serve the page at "main.mysite.com/data.php" subdomain.
I also want to keep the url at "customer.mysite.com/data.php" for the two cases.
My complete htaccess file is currently :
# This will enable the Rewrite capabilities
RewriteEngine On
RewriteBase /
# This rule will convert request urls like /category/page?id=1 to /?c=category&p=page&id=1
# Redirect to main page, which is Single Page Application and then manage to open the new tab
RewriteRule ^([A-Za-z]*)\/([A-Za-z]*)([?]?[A-Za-z0-9=&]*)$ /?c=$1&p=$2 [NC,R,QSA]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
# First, this checks to make sure the connection is not already HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [NC]
# This rule will serve pages from main.mysite.com when browsed with customer.mysite.com
# By removing the [R=301], it makes an internal redirect, keeping the original url in the browser
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://main.mysite.com/$1 [L,NC,QSA]
# Disable Directory Listing
Options -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
However, when I browse "customer.mysite.com/page.php", I am redirected to "main.mysite.com/page.php", which is not what I want.
First , to redirect /category/page?id=1 to /?c=category&p=page&id=1 :
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^([A-Za-z]+)\/([A-Za-z]+)$ /?c=$1&p=$2 [NC,R=301,QSA]
change this : RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [NC]
to this RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
Because %{HTTP_HOST} it is request header including your target host
Moreover :
I f you handled error file like that , when there is no file in that target looping will happen so it is better to handle that like this :
replace this :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://main.mysite.com/$1 [L,NC,QSA]
With this :
RewriteCond %{HTTP_HOST} !^(www\.)?main.mysite.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://main.mysite.com/$1 [L,NC,QSA]
#then you could handle the error that not found in main by this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /path/to/error/page [L]
By adding the proxy flag [P] to the rule, the server makes an internal redirect, keeping the browser url unchanged. Normally, this would work by not specifying the R=301 flag, but it'S not enough when the rule is changing domain/subdomain.
What worked:
RewriteRule ^(.*)$ https://main.mysite.com/$1 [P,L,NC,QSA]
Note that the L flag is not required with P as it is added implicitely, as no other rules can be executed after that.

How to route multiple domains to multiple subfolders

I have a setup where I have a couple of sites hosted in different subfolders in the root of my FTP
ROOT
-site1folder
-site2folder
I have 2 domain names not associated with the account. I have changed the DNS records of the domains to point to my hosting account but I need the 2 different URLs to go to the correct subfolder to load the correct site rather than transfer the domains. The domains are
www.site1.com
www.site2.com
Ideally I would like site1 to load the contents of the site1folder and the same for site 2 and its corresponding folder.
I currently have a .htaccess file in my root which I have mashed together from looking at different posts. I am a newbie to .htaccess. I am currently trying to get site 1 to point to the site1 folder
Options +FollowSymLinks
#Turns the rewrite engine on.
RewriteEngine on
#Fix missing trailing slash character on folders.
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]
RewriteBase /website1
#www.site1.co.uk and site1.co.uk will map to the folder
RewriteCond %{HTTP:Host} ^(?:www\.)?site1\.co.uk
RewriteRule (.*) /site1 [NC,L,NS]
What happens when I load this is I get the contents of the site1 folder but at this URL site1.co.uk/site1
I don't want the URL to change at all. I just want it to load the contents of the subfolder it is pointed to.
Ok people I managed to solve this one myself in the end after lots of head banging and reading a lot of the docs to decyfer others code. Here is what I did...
Options +FollowSymLinks
RewriteEngine on
#========================================================================
# FIRST Handle the http requests first before removing the additional url junk
#========================================================================
#rule for site1.com to link to site1folder directory
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/site1folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1folder/$1
#rule for site2.com to link to site2folder directory. Its the same as above just with site2 URL and subfolder
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
RewriteCond %{REQUEST_URI} !^/site2folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site2folder/$1
#==========================================================
# SECOND Remove the additional url junk once the new url is loaded
#==========================================================
#rule for site1 url rewrite to remove /site1foler/index.php from the URL
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^(/)?$ site1folder/index.php
#rule for site2 url rewrite to remove /site2foler/index.php from the URL. Again its the same as above just with the site2 URL and sub folder info.
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
RewriteRule ^(/)?$ site2folder/index.php
Hopefully you can see where the repetition is in this so if you wished to add more sites down the line to it you could by copying and pasting the data and changing the site URL and sub folder to match the additional ones you wish to add.
I hope this has managed to help some of you. Also if you can see issues with this then it would be very much appreciated as I am a newbie at .htaccess files and as you can imagine, I figured as it works, it must be right.
I have used this in a Dedicated Windows Server using xampp. It works fine to me with SSL
# mydoamin.com starts ############################
RewriteCond %{HTTP_HOST} ^(www.)?mydoamin.com$
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# mydoamin.com ends ############################
# mydoamin.in starts ############################
#RewriteCond %{HTTP_HOST} ^(www.)?mydoamin.in$
#RewriteCond %{HTTPS} !on
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# mydoamin.in ends ############################

htaccess subdomain rewrite keep www

I've set up wildcard domains locally for testing on .dev
I'm trying to rewrite the following URL:
http://location.domain.dev/
to
http://www.domain.dev/site/location
I would like any requests with www in the subdomain to always go to www.domain.dev but if any request is made to location.domain.dev, I would like to keep that request in the address bar (i.e i dont want people to see the underlying change)
I currently have the following in my .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.dev
RewriteRule ^(.*)$ http://domain.dev/site/%1 [QSA,NC]
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
Is this even possible?
You're pretty close. In order to not redirect the browser (causing the address bar to change) you need to get rid of the http://domain.dev part of the rewrite rule's target:
RewriteRule ^(.*)$ /site/%1/$1 [QSA,NC]
assuming that both *.domain.dev and www.domain.dev have the same document root. If they're different, you may have to enable mod_proxy and add a P flag so that the request gets proxied instead of redirecting the browser:
RewriteRule ^(.*)$ http://domain.dev/site/%1/$1 [QSA,NC,P]

Redirect folder on parked domain to main domain

I am moving a client's site from static HTMl to a WordPress site. This has also involved setting up a new domain. I have the legacy domain set up as a parked domain on my server and can successfully redirect all requests for the parked domain to the main domain. Here is my .htaccess in full:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Rewrite from parked domain to new domain
RewriteCond %{HTTP_HOST} ^parked-domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.parked-domain.co.uk$
RewriteRule ^/?$ "http\:\/\/www\.main-domain\.co\.uk" [R=301,L]
# All requests hit www.domain.co.uk to prevent duplicate content
RewriteCond %{HTTP_HOST} !^www.main-domain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.main-domain.co.uk$1 [L,R=301]
However, I am coming unstuck when I try to redirect requests for specific pages on the parked domain to pages at the main domain.
For example, requests for parked-domain.co.uk/html/about_us.html should redirect to main-domain.co.uk/about-us/
I've a hit a brick wall (in spite of many hours of forum-searching) and any help would be gratefully received; this is rage-inducing.
What happens when you simply add
Redirect/html/about_us.html http://www.main-domain.co.uk/about_us.html
to that file?

Resources