in Education by
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)

1 Answer

0 votes
by
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.

Related questions

0 votes
    I am trying to write a rule which says xyz.com/hotels_in_someplace will direct to xyz.com/test.php?place ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Facing issue in session with the upgrade of my application to Spring 4.1.9 and Hibernate 4.3.11.. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I am trying to deserialize a JSON string but I get an error: var response = jss.Deserialize(responseValue) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I am looking to get row count to check if same email is already in database or not. i have tried ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I'm creating a very basic AI with Tensorflow, and am using the code from the official docs/tutorial. Here's my ... Tensorflow 1.13.1. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Star Ltd has received application for 48 crore (issue size was50crore ) discuss the document filled with a register of companies Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    have MS Teams (version 1.4.00.4167 64 bit last updated on 23Feb 21) application installed. When I join the meeting audio ... share the advise here what best can we do to fix this....
asked Mar 10, 2021 in Technology by JackTerrance
0 votes
    The computer connected with each other should behave in some particular manner and rules.what these rules/manner are called….??? Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Write down the rules for converting E-R diagram to relations with example. Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    ____________ learning blends rules created by humans with data to develop answers to a problem. Select the correct answer from below options A)Traditional B)Machine...
asked Dec 3, 2020 in Technology by Editorial Staff
0 votes
    Explain : Opposition parties held a meeting in Mumbai to resist the Ruling party. Will take up the issue of farmers? Please answer the above question....
asked Aug 14, 2022 in Education by JackTerrance
0 votes
    Explain the following statements by giving reasons : Political parties can concentrate on one particular issue. Please answer the above question....
asked Aug 14, 2022 in Education by JackTerrance
0 votes
    Describe the Kashmir issue between India and Pakistan. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    I'm working on migrating/rewriting some Java generics in C#. I'm getting an error that I don't ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    Has any else experienced when logging into to sitecore it says too many users are logged but when you ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
...