![Hamaas447](https://vmapp.org/images/player/000default.jpg)
: URL rewrite from www.example.com/subdirectory to example.com/subdirectory I need a solution for the following problem: I use a CMS and want the backend to only be available at http://example.com/backend
I need a solution for the following problem:
I use a CMS and want the backend to only be available at example.com/backend and not at www.example.com/backend. The rest of the site should be available at example.com.
How do I change my .htaccess file to achieve this? I already have a rewrite rule from (non-www) to
Here's what I currently have in my .htaccess file:
##
# Uncomment the following lines to add "www." to the domain:
#
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) www.example.com/ [R=301,L]
#
# Uncomment the following lines to remove "www." from the domain:
#
# RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
# RewriteRule (.*) example.com/ [R=301,L]
#
# Make sure to replace "example.com" with your domain name.
##
So, the first bit is the redirect from non-www to It works on the domain part of the URL. As explained, I need a rewrite rule from the backend login at www.example.com/backend to example.com/backend.
More posts by @Hamaas447
1 Comments
Sorted by latest first Latest Oldest Best
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} ^example.com$ [NC]
RewriteRule (.*) www.example.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(backend.*) example.com/ [R=301,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.