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.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)