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 8107379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:45:04+00:00 2026-06-06T00:45:04+00:00

This is the 1st time I am using stackoverflow, I usually find answers to

  • 0

This is the 1st time I am using stackoverflow, I usually find answers to my questions about development thanks to Google, or with the help of some friends. Not this time !

I am in trouble with a .htaccess file where I want to define a double rule.
Initally I had this code for URL rewriting :

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) /index.php?query=$1&%{QUERY_STRING} [L]

It is working like a charm, but I saw that many of the pages of the website indexed by Google where duplicated on a subdomain of my website, so I decided to add this code in the .htaccess :

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

Please notice that I have added this code, just after the RewriteEngine on.
The result is almost what I expect, the 301 redirection from subdomain such as mail.domain.com/mypage.html is working and leads to http://www.domain.com/mypage.html but the second rule for URL rewriting pages is like cancelled ! So all pages which use the second rule have a 404 error.

I have tested many different things but couldn’t figure out how to fix that ?
Anyone has a tip to help me success ?

Thanks in advance guys !

  • 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-06-06T00:45:05+00:00Added an answer on June 6, 2026 at 12:45 am
    RewriteCond %{HTTP_HOST} !mydomain.com/$
    

    This condition always matches, since you are asking for a hostname that does not end in mydomain.com/; %{HTTP_HOST} will never end in a slash, since it only contains the hostname with no path. Since the condition always matches, its RewriteRule is always in effect, and it is marked as [L] (last rule). I have no idea why it does not result in an redirection loop, probably some short-circuit logic in mod_rewrite that stops the rewriting when the URL hasn’t been changed.

    What you probably want is this:

    RewriteCond %{HTTP_HOST} !=www.mydomain.com
    RewriteRule ^(.*) http://www.mydomain.com/$1 [R=301,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Entity Framework (1st time) on a SQL 2005 database for a data
I am using MyEclipse 7.0 for the 1st time. Previously I was using MyEclipse
I've typically done this using edmx's but this time in order to use cascading
All, This is the first time I am using MySQL and hence listing all
I am using the Validationprovider control for the 1st time. I've had limited success
I'm using R to do some time series analysis using zoo and chron. I've
I have 3 arrays like this: 1st Array ( [0695] => Array ( [loan_number]
I have 1st popup, and this 1st popup opens 2nd popup Code: <view-state id=paneMaintenance
I'm in the process of building a site with CodeIgniter. This is the 1st
This is the example table: Column | 1st record | 2nd record | 3rd

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.