Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Redirects from subdirectories

Featured Replies

I've got my site at www.MyDomain.com. In cPanel I've specified some addon domains for my clients like www.ClientDomain.com. These client sites are hosted in the same server as www.MyDomain.com and one can access them by www.MyDomain.com/clientsite/. Is there a way to stop this from happening? I'm afraid Google will penalize for duplicated content and also the clients site should only be accessible from www.ClientDomain.com and nowhere else.

 

I tried setting a permanent redirect in cPanel for www.MyDomain.com/clientsite/ but it didn't work.

 

Anybody know how to solve this?

  • Author

Are your client sites in a folder, such as: www.mydomain.com/clients/client-site ?

 

They're at www.mydomain.com/client-site/

 

So what I currently have is something like

 

www.mydomain.com/client-site1/

www.mydomain.com/client-site2/

www.mydomain.com/client-site3/

www.mydomain.com/client-site4/

Edited by modipeluri

You've made it hard for yourself there!

 

Try this .htaccess in the root of www.mydomain.com:

 

RewriteEngine On
RewriteBase /

RewriteRule ^(client-site1|client-site2|client-site3)\/?(.*)$ http://www.$1.com/$2 [QSA,R=301,L]

 

Just change 'client-site1' etc. to the actual folder names. There may be a better way, but this will work without messing up links to all the other folders on your site (/css, etc.)

  • Author

Okay, so I tried that but to no avail. In what format should I write the client-site address'?

I tried something like this:

 

RewriteRule ^(www.mydomain.com/client-site)\/?(.*)$ http://www.$1.com/$2 [QSA,R=301,L]

 

Am I typing the url in a wrong way?

Edited by modipeluri

I dont understand why you can just delete the folders.

 

Your client websites are on www.clientdomain.com and also in folders on your domain, then why not just delete the folders? Then they are only accessbile from the clients own domain name?

 

If the foldered version is for development, then why dont you make a locked sub domain so v2.clientdomain.com which is password protected and not crawled?

  • Author

I dont understand why you can just delete the folders.

 

Your client websites are on www.clientdomain.com and also in folders on your domain, then why not just delete the folders? Then they are only accessbile from the clients own domain name?

 

If the foldered version is for development, then why dont you make a locked sub domain so v2.clientdomain.com which is password protected and not crawled?

 

I can't delete the folders because the client domains are on addon domain on my server. This is where their website files are.

 

I'm not very experienced in server management so I never thought about it but that sounds like an excellent idea.

  • Author

Okay, so I tried that but to no avail. In what format should I write the client-site address'?

I tried something like this:

 

RewriteRule ^(www.mydomain.com/client-site)\/?(.*)$ http://www.$1.com/$2 [QSA,R=301,L]

 

Am I typing the url in a wrong way?

 

So from what I've gathered you need to escape symbols with \ right?

 

RewriteRule ^(mydomain\.com\/client-site\/)\/?(.*)$ http://www.$1.com/$2 [QSA,R=301,L]

 

Could someone confirm if this is the correct syntax? I'm getting really worried about the directory showing up in Google search results >_<

Just use the exact code I gave you. Don't add www.yourdomain. Don't add anything. Just change the words 'client-site1' etc. to the folder names. So if you owned my website it would be:

 

RewriteRule ^(andylockett|client-site2|client-site3)\/?(.*)$ http://www.$1.com/$2 [QSA,R=301,L]

Edited by andyl

  • Author

Just use the exact code I gave you. Don't add www.yourdomain. Don't add anything. Just change the words 'client-site1' etc. to the folder names. So if you owned my website it would be:

 

RewriteRule ^(andylockett|client-site2|client-site3)\/?(.*)$ http://www.$1.com/$2 [QSA,R=301,L]

 

Thanks for your patience Andy. I added the code to my .htaccess file but it didn't help, mydomain.com/client-site still didn't redirect to client-site.com

 

Then I noticed that there might be something fishy going on with one of the top level links (congress) having the same name as the folder (congress). And whenever going to mydomain.com/congress I wouldn't get the homepage but I'd end up at the congress page.

 

So, I changed the folder name and my addon domain home folder name to something else. Now going to mydomain.com/client-site (the new folder name) gives me a 404 not found page. While going to mydomain.com/congress redirects me to www.congress.com :D and I have no idea how that got in the mix.

 

Anyhow, thanks for the help!

Hmm that code should work, it works perfectly on my server when I test it. Not sure what you've done there, but it you're happy...

  • Author

Hmm that code should work, it works perfectly on my server when I test it. Not sure what you've done there, but it you're happy...

 

I'm guessing that there's something interfering with my code. The .htaccess I'm using now is from the boilerplate template with the default settings. Also there's another .htaccess file in the client-side folder itself which has the following lines:

 

# 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

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^clientsite\.mydomain\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.clientsite\.mydomain\.net$
RewriteRule ^/?$ "http\:\/\/clientsite\.net\/" [R=301,L]

 

The .htaccess in the root folder is pretty long but I can post that too if you think it might be helpful. I'm kinda happy with how things are now but at the same time I'm interested in finding a solution and understanding how these things work.

  • Author

Okay so I think I got this solved. Thanks all for the help!

 

The solution I found was to disable index in folders. Now my own site at mydomain.com works fine, and if I try to go to a subfolder I will get a 404 not found error as defined in the .htaccess file.

 

Options -Indexes
DirectoryIndex index.html index.php /404.php

 

I also made a public folder with a separate .htaccess file with the line:

Options +Indexes

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.