htaccess apending parked domains subfolder to the URL - .htaccess

I created a website for a client and as per normal with our sites included an htaccess file to redirect any non-www traffic to the www. subdomain.
The client has now added a parked domain as a subfolder where they want to host another site. If you go to www.parkeddomain.com then it works, displaying the site in the PARKEDDOMAIN.COM subfolder. However if you go to parkeddomain.com then the htaccess redirects you to www.parkeddomain.com/PARKEDDOMAIN.COM. How can I stop it appending the subfolder to the URL?
This is the contents of the htaccess file:
Options +FollowSymLinks
RewriteEngine on
# Redirect old URLs to new URLs
Redirect /jewelry-the-experience /custom-made-jewelry
Redirect /jewelry-the-process /custom-made-jewelry
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*)$ /handle-url.php [L]

Add the following rule just before the existing one.
RewriteCond %{HTTP_HOST} ^parkeddomain\. [NC]
RewriteRule ^(?:parkeddomain\.com/?)?(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} !^(www|parkeddomain)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
We catch the no-www parked domain first and redirect without its sub-directory. This makes sure the existing rule is always redirecting the primary domain only.

Related

Using .htaccess to redirect to https, subfolder and prevent naked domain URLs?

I'm having a heck of a time constructing an .htaccess file to do everything that I need. I have a domain that is only hosting a forum in a /forums subdirectory. I have no landing page, nor do I intend to.
So I want to redirect the root domain to the /forums subfolder, force https and THEN PREVENT naked domains from being allowed.
I've got it all working except users can still manually access/choose a naked domain variant. Some users have been bookmarking the naked domain variant and I want to force them, and all users, back into the www. prefix.
The code below takes http:www.example.com or http:example.com and forces it to https://www.example.com/forums/. The problem is users are still able to manually access https://example.com/forums.
I've tried a bunch of different things to force the forums in the /forums subdirectory to always use a www. prefix, but nothing has worked thus far:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) http://www.example.com/forums [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]
With your shown samples/attempts could you please try following. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine on
##Handle non https all urls here.
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
##Handle non www urls here.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
##Handle no uri link with no www page.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^/?$ http://www.example.com/forums [R=301,L]
##Handle no uri link with www page.
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^/?$ https://www.example.com/ [R=301,L]

Sub-domain Getting Issue with .htaccess

I have a domain "example.com" and i use following redirection code to redirect it to www in .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
it is working fine until i generate a sub-domain with that domain like "abc.example.com" but it's getting conflicts with htaccess and redirecting the sub-domain to "www.abc.example.com/abc/"
You can use:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|abc)\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

how to redirect all pages to another domain, except home page, using .htaccess

I want to redirect all pages (except for the home page) from one domain to another.
How do I do this?
This is the rule you have to add to your htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
#if not root
RewriteCond %{REQUEST_URI} !^/?$ [NC]
#redirect
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

.htaccess to redirect multiple domains, non-www. and non-https to the one single domain and preserve the path

I have a few old domains that resolve to the new site. I just switched on SSL. The old blog posts from old sites have been merged into the new site with the same paths.
I need .htaccess code to redirect multiple domains, non-www. and non-https to the one single domain with www and https. Essentially, if it doesn't begin https://www.mavencomputers.com.au/ then redirect it to that whilst preserving the rest of the path, ie, not redirecting to home.
I currently have
RewriteCond %{HTTP_HOST} ^artisan\-solutions\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.artisan\-solutions\.net\.au$
RewriteRule ^/?$ "https\:\/\/www\.mavencomputers\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mavencomputers\.com\.au$1
RewriteRule ^(.*)$ "https://www.mavencomputers\.com\.au\/%1" [R=301,L]
You can use this .htaccess code:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mavencomputers\.com\.au$
RewriteCond %{HTTP_HOST} !^images\.mavencomputers\.com\.au$
RewriteRule ^(.*)$ https://www.mavencomputers.com.au/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You can test this file with this tool.

redirecting parked domain and their old urls to new domain

I need some help with htaccess and redirection. I have a domain - sp-gd.com. On top of this domain I have 2 parked domains; suryaprasetya.com and suryaprasetya.com.au.
I have already set up 301 redirection for the parked domains so it will go to sp-gd.com. What I want to do is for the old urls from parked domains to redirect to new domain.
Note that I have switched the hosting and it is under sp-gd.com
heres my htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.+) /index.php
RewriteCond %{HTTP_HOST} ^suryaprasetya\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.suryaprasetya\.com$
RewriteRule ^/?$ "http\:\/\/www\.sp\-gd\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^suryaprasetya\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.suryaprasetya\.com\.au$
RewriteRule ^/?$ "http\:\/\/www\.sp\-gd\.com" [R=301,L]
have tried putting
RewriteCond %{HTTP_HOST} ^suryaprasetya\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.suryaprasetya\.com\.au$
RewriteRule ^/portfolio http://www.sp-gd.com [R=301,L]
and its not working
Basically what I wanna do is to redirect any urls requested using parked domain names to the new domain...
Change your 2 R=301 rules to this:
RewriteRule ^(.*)$ http://www.sp-gd.com/$1 [R=301,L]
Weird, I have the exact same changes in my .htaccess file:
RewriteCond %{HTTP_HOST} ^hostkingonline\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.hostkingonline\.com$
RewriteRule ^/?$ "http\:\/\/www\.hostking\.co\.za" [R=301,L]
They seem to work quite well.
Can't see any difference in mine compared to yours.
If all else fails and using cPanel as your control panel you can redirect it via the Parked Domains icon and manage redirection option.
Also found this that may be useful for apache changes: Problems redirecting old domain to new with Apache and htaccess

Resources