Redirect domains
Hello,
How can I redirect example.com/hosting to example-hosting.com ?
tried using htaccess and redirect option on cpanel, is the only way to redirect with PHP code or have htaccess script to do 301 redirect?
-
Hello @Flegy, Can you verify what happens when you setup the redirect from within cPanel using the Redirects option? Do any existing redirect rules exist in the .htaccess file in the document root of that website? Note that if you are looking for a custom Mod_Rewrite rule to try, here's a link to a StackOverflow thread with an example: How to redirect subdirectory to new domain with masking? Thank you. 0 -
Sorry for slow reply. example.com is main domain and it redirect to subfolder. So now when I enter example.com/anyothersubfolder it open another web. public_html .htaccess #AddDefaultCharset On #AddDefaultCharset UTF-8 # .htaccess main domain to subfolder redirect # Copy and paste the following code into the .htaccess file # in the public_html folder of your hosting account # make the changes to the file according to the instructions. # Do not change this line. RewriteEngine on # Change yourdomain.com to be your main domain. # Change 'subfolder' to be the folder you will use for your main domain. # Don't change this line. # Change 'subfolder' to be the folder you will use for your main domain. RewriteCond %{HTTPS} off RewriteRule ^(.*)$ 'https://www.domain.tld/$1' [R=301,L] RewriteCond %{http_host} ^domain.tld [NC] RewriteRule ^(.*)$'https://www.domain.tld/$1' [R=301,L] RewriteCond %{HTTP_HOST} ^('http://www.)?domain.tld$' RewriteCond %{REQUEST_URI} !^/panel/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteRule ^(.*)$ /panel/$1 # Change yourdomain.com to be your main domain again. # Change 'subfolder' to be the folder you will use for your main domain # followed by / then the main file for your site, index.php, index.html, etc. RewriteCond %{HTTP_HOST} ^(0 -
example.com is main domain and it redirect to subfolder
Hello @Flegy, Is it setup that way on purpose? If so, is there any reason you prefer to use a redirect instead of simply uploading the website contents to the public_html directory itself? Thank you.0 -
I have many webs and want to have all organized. Its hard when having a lot of folders what use the main web, so like to have all separated. 0 -
Hello @Flegy, Do you have root access to this server? If so, you can use the following steps to modify the default document root for the domain name utilized as the primary domain name of the account: 1. Update the "documentroot" value to the new path in the following files: /var/cpanel/userdata/username/domain.tld /var/cpanel/userdata/username/domain.tld_SSL 2. Remove the existing cache files: rm /var/cpanel/userdata/username/domain.tld.cache rm /var/cpanel/userdata/username/domain.tld_SSL.cache
3. Rebuild the cache files and the Apache configuration file:/scripts/updateuserdatacache /scripts/rebuildhttpdconf
4. Restart Apache:/scripts/restartsrv_httpd
This would allow you to point the domain name to the correct document root without using a redirect. Thank you.0
Please sign in to leave a comment.
Comments
5 comments