I have a site1.com as my primary site. I created two folders in the root directory "site1" & "site2". I used Htaccess to redirect site1.com's traffic to folder "site1". Site2 works too as site2.com using directory "site2".
Now, the issue is because site1 is primary, I'm able to visit site2 via site.com/site2 . What rewrite can I use to ignore site.com/site2, or show a 404 when site1.com/site2 is visited and still allow for site2.com to work?
Here is my htaccess file.
RewriteEngine on
Options -MultiViews
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/site1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1/$1
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^(/)?$ site1/index.php [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
My folder hierarchy is
-root
.htaccess
-site1 folder
- index.php
-site2 folder
- index.php
Due to godaddy's primary domain setup, even though when i visit site.com it loads info from site1 folder, if i visit site1.com/site2 it will load site 2
I went in a different direction for a similar problem on Godaddy.
Rather than looking for just hits from site1.com and redirect them, I sent any requests hitting the site2 subfolder / subdomain to site2.com with this:
RewriteCond %{HTTP_HOST} !^site2\.com$ [NC]
RewriteRule ^(.*)$ http://site2.com/$1 [R=301,L]
Now any requests that worm their way into that site1.com/site2 subfolder get 301'd to the appropriate page on site2.
I don't consider myself an expert by a longshot and would welcome critiques from those with more experience.
Untested code: I believe you can do the following
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^site2/(.*)$ http://site1.com/$1 [R=301]
This will (or should) redirect the client from http://site1.com/site2/my/awesome/page.php to http://site2.com/my/awesome/page.php.
Related
I don't know much about the .htaccess file and need some assistance please. I have a few websites hosted one one CPanel account. I didn't want to have my "main" site stored directly in the public_html folder, so I moved it into a subfolder and then found this .htaccess configuration that allows me to load my main site from that subdirectory. So that is working.
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/example_directory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /example.com/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
So as I said, the above .htaccess will allow me to store my site files in a different folder rather than right at the root. But now I'm trying to force a redirect for this site over https as well. I found this site here:
Force Website to Use SSL
But, since I really don't understand the .htaccess file I'm having trouble integrating these two features together. Any help on this would be greatly appreciated. Thanks.
I'm pretty certain I figured this out myself. I just simply had to add this to the end of my .htaccess file:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
and it works like a charm. Full .htaccess file looks like this, which changes the folder directory for the site to use and then forces it over https.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example_directory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
I have been at this for a number of hours and cannot get this to work. I have other redirects in this .htaccess file that do work.
I need to redirect as follows.
mydomain.com/dir/subdir/myfile.php to myotherdomain.com/dir/my_index.php
Note that mydomain.com and myotherdomain.com both point to the same root directory.
Here's my code.
RewriteCond %{HTTP_HOST} ^(www.)?postle.com$
RewriteCond %{REQUEST_URI} !^/pi_www/hardface/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /pi_www/hardface/$1
RewriteCond %{HTTP_HOST} ^(www.)?hardfacetechnologies.com$
RewriteRule ^(/)?$ postle_hft/index_hft.php [L]
I have tired all the permutation of this I can think of and nothing works. I really would appreciate some help.
You can use this rule in /dir/subdir/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^myfile\.php$ http://myotherdomain.com/dir/my_index.php [R=302,NC,L]
If you want to avoid external redirect then:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^myfile\.php$ /dir/my_index.php [NC,L]
should also work as both domains point to same site root.
In the .htaccess file in your document root, try:
RewriteCond %{HTTP_HOST} =mydomain.com
RewriteRule ^dir/subdir/myfile\.php$ http://myotherdomain.com/dir/my_index.php [R=302,L]
The order of directives is important. This should come after your canonical www redirect, but before any internal rewrites, and before any redirects that might conflict.
This also assumes that your canonical URL is the bare domain (ie. not the www subdomain) - like with the example in your question. To match the bare domain or the www subdomain (and make it case-insensitive) then change the RewriteCond directive to:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]
Change the temporary (302) redirect to permanent (301) when you are sure it's working OK. (301 redirects are cached by the browser, so makes testing troublesome.)
Its a godaddy root structure where we have to keep all files in the root directory to access the url as www.example.com, and any other domain has to be in the root directory of the primary domain with which the payment is done, pretty crappy structure from go daddy.
To avoid the clutter I made the one more folder inside root as /example/.. and pushed all the files form root to the mentioned folder,
earlier it was working fine, I had purchased ssl certificate but after the certificate expires, it was not opening the domain so I have made the rewritecond %{HTTPS} !off form rewritecond %{HTTPS} !on and now the redirection is not at all working,
I am really bad at .htaccess, so looking for best advice.
rewriteengine on
rewritecond %{HTTPS} !off
rewritecond %{HTTP_HOST} ^www.example.com$ [OR]
rewritecond %{HTTP_HOST} ^example.com$
rewriterule ^$ "http\:\/\/example\.com\/index\.php" [R=301,L] #51w512ed4b49c
rewriterule ^$ "http\:\/\/example\.com" [R=301,L] #51w512ed4b49c
rewritecond %{REQUEST_FILENAME} !-f
rewritecond %{REQUEST_FILENAME} !-d
rewritecond %{REQUEST_FILENAME} !-l
rewriterule ^(.*)$ /example/$1 [QSA]
rewritecond %{HTTPS} !off
rewritecond %{HTTP_HOST} ^(www.)?example.com$
rewriterule ^(/)?$ index.php [QSA,L]
I want the redirection from www.example.com to example.com
and url should look as example.com/index.php or example.com not as example.com/example/index.php or example.com/example/
Now I don't want the SSL and how to update the .htaccess
Why is internal server error is coming just for the example folder and not for any other folder.
Folder Structure in godaddy panel:
straight to the point.
I have a web hosting with 2 domains pointing to the root directory of the hosting.
I have 2 seperate projects in the root directory both symfony2
I need to redirect the domains to the seperate directories using .htaccess.
My current .htaccess file in the root folder
RewriteEngine On
#www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301, L]
#domain1
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/domain1/web
RewriteRule ^(.*) /domain1/web$1 [L]
#domain2
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/domain2/web
RewriteRule ^(.*)$ /domain2/web$1 [L]
now when I type in domain1 in the adress bar. The project works correctly. What I get in the adress bar is: "domain1.com/domain1/web" And I'd like to get rid of the domain1/web part so that the functionality stays. Do I somehow use rewrite base? Or is there an other way for me to get my result? please help. Note that I'm not really used to working with .htaccess so please be gentle :)
I have Codeigniter installed and working for my main site.
But I am now trying to add an add-on domain to the same hosting account, so I can have two sites running on the same hosting. Add-on domains make a new folder in the main public_html folder to store the web files.
How can I get Codeigniter to ignore this directory? The site doesn't load properly when I try and view it.
I have an SSL on the main site too and redirection for www URLS. Here's my .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.mysite\.co.uk$ [NC]
RewriteRule ^(.*)$ http://mysite.co.uk/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (site|sections|here)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} onsite|sections|here)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
I have multiple domains on the same hosting two of which use CI. Don't change the main htaccess, only the one inside the folder containing the CI install. If your main site is directly in the public_html folder you may have to move it to it's own folder and redirect your URL to that folder, other than that this really shouldn't cause any issues.