Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I need a solution for the following problem:

I use a CMS and want the backend only be available at http://domain.com/backend and not at http://www.domain.com/backend.

How do I have to change my .htaccess file to achieve this? I already have a rewrite rule from HTTP (non-www) to www.

Here's what I currently have in my .htaccess file:

  ##
  # Uncomment the following lines to add "www." to the domain:
  #
RewriteCond %{HTTP_HOST} ^shaba-baden\.ch$ [NC]
RewriteRule (.*) http://www.shaba-baden.ch/$1 [R=301,L]
  #
  # Uncomment the following lines to remove "www." from the domain:
  #
  #   RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  #   RewriteRule (.*) http://example.com/$1 [R=301,L]
  #
  # Make sure to replace "example.com" with your domain name.
  ##

So, the first bit is the redirect from HTTP to www. It works on the domain part of the URL. As explained, I need a rewrite rule from the backend login at http://www.shaba-baden.ch/contao to http://shaba-baden.ch/contao

share|improve this question
    
Can you update the question to quote the code inside your .htaccess file so we know what you already have in there? –  dan Nov 20 '13 at 1:23
add comment

1 Answer

It sounds like you have a specific directory that you want to be accessed without www while everything else would be accessed with it.

You will need both rewrite rules (one of which you currently have commented out) and you will need to add some extra conditions to each:

RewriteCond %{REQUEST_URI} !^/backend$
RewriteCond %{HTTP_HOST} ^shaba-baden\.ch$ [NC]
RewriteRule (.*) http://www.shaba-baden.ch/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/backend$
RewriteCond %{HTTP_HOST} ^www\.shaba-baden\.com$ [NC]
RewriteRule (.*) http://shaba-baden.com/$1 [R=301,L]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.