Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6971297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:49:19+00:00 2026-05-27T16:49:19+00:00

I’m trying to set up a rewrite rules for a website, but there is

  • 0

I’m trying to set up a rewrite rules for a website, but there is one issue so far.
At the moment, this is set up locally, for testing.

The setup is a main root folder, in which there are a numbers of subfolders, and some of them are subdomains. The subdomains are already mapped in the httpd.conf, and they are working properly.

example.com
sub.example.com
something.example.com
...

With the following folder structure:

C:/website
C:/website/css
C:/website/images
C:/website/sub (subdomain)
C:/website/something (subdomain)

So, the files in the ‘website’ folder are used by example.com, and also the folders not mapped as subdomains. In each subdomain there are the specific files that each subdomain uses, but also they use some common files from the parent directory (not really relevant for the issue). For the main website (and also for the subdomains), everything goes through the index.php file (already solved with rewrite rules), so no direct access to the other files (also not very relevant).

So my issue now is that if accessing the subdomain without ‘www’ (sub.example.com), it is fine. If accessed with ‘www’ (http://www.sub.example.com), it goes to the main site.

Here is my .htaccess file (rewrite rules):

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteRule \.(css|jpe?g|gif|png|js)$ - [L]

RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

RewriteRule ^([^/\.]+)/?$ /index.php?cmp=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?cmp=$1&page=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?cmp=$1&subsection=$2&page=$3 [L]

Thing to note: Almost same concept for main controller (index.php) would be for the subdomains, so most of these rules will be in the subdomain’s .htaccess file.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:49:19+00:00Added an answer on May 27, 2026 at 4:49 pm

    This rule is strange:

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    

    I’m doing almost exactly what you describe, but there’s no point of adding “www” if there’s already something. What I do is:

    # if domain name without "www", add them:
    RewriteCond %{HTTP_HOST} ^mydomainname\.(fr|com|net|org|eu) [NC]
    # add www *and* force redirection :
    RewriteRule (.*) http://www.mydomainname.%1$1 [QSA,R=301,L]
    

    So you only add www when needed i.e. when there’s no ‘sub’ at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.