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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:44:37+00:00 2026-05-27T02:44:37+00:00

I am trying to set up a my development, staging, and production servers in

  • 0

I am trying to set up a my development, staging, and production servers in such a way that I can create a single .htaccess file and use environment-specific variables to determine which rewrite actions to execute. I want to use the name of the specific server to do URL rewrites, but I seem to be running across some problem (likely trivial) that I simply can’t solve.

The goal of this .htaccess file is to:

  • Rewrite URL to WWW on production server only
  • Send .html filenames as foo query vars
  • Send .htm filenames as bar query vars
  • Be able to modify or add additional rules to specific servers

Similar to this suggested outline, my htaccess file looks like this:

Options +FollowSymlinks
RewriteEngine On

# Production

# Redirect to WWW on production server
RewriteCond %{SERVER_NAME} =www.domain.com [NC]
RewriteCond %{HTTP_HOST} !^www\.domain.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301,NC]

RewriteCond %{SERVER_NAME} www.domain.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.html index.php?foo=$1 [NC,L,QSA]
RewriteRule ^(.+)\.htm index.php?bar=$1 [NC,L,QSA]

# Staging
#RewriteCond %{SERVER_NAME} =staging.domain.com [NC]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.+)\.html index.php?foo=$1 [NC,L,QSA]
#RewriteRule ^(.+)\.htm index.php?bar=$1 [NC,L,QSA]

# Development
RewriteCond %{SERVER_NAME} =localhost [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.html index.php?foo=$1 [NC,QSA,L]
RewriteRule ^(.+)\.htm index.php?bar=$1 [NC,QSA,L]

The problem that I’m having is that no matter which order I list the servers in the .htaccess file, only the first server listed seems to rewrite properly. When deployed on the other servers I am noticing that the foo test case is skipped over and is instead returned as the bar result. I have been able to determine that this seems to be coming from the second RewriteRule in the first server section, but I can’t figure out why.

More information can be provided upon request.

  • 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-27T02:44:38+00:00Added an answer on May 27, 2026 at 2:44 am

    I think maybe you need to replace the SERVER_NAME checks with HTTP_HOST and add a $ to your html/htm checks.

    # Redirect to WWW on production server
    RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301,NC]
    
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.html$ index.php?foo=$1 [NC,L,QSA]
    RewriteRule ^(.+)\.htm$ index.php?bar=$1 [NC,L,QSA]
    
    # Staging
    #RewriteCond %{HTTP_HOST} ^staging\.domain\.com$ [NC]
    # otherwise, it would look same as Development
    
    # Development
    RewriteCond %{HTTP_HOST} ^localhost$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.html$ index.php?foo=$1 [NC,QSA,L]
    RewriteRule ^(.+)\.htm$ index.php?bar=$1 [NC,QSA,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can set up Apache to run locally, specifically
I'm trying to set up a development environment on my aging Macbook Pro that
I am trying to set up a development environment for our web server. I
I'm trying to set up a development environment for a legacy Rails 2.3.8 project.
Platform: Windows XP Development Platform: VB6 When trying to set an application title via
Im trying set the single table inheritance model type in a form. So i
I am trying to set up a development environment to play around with developing
I am currently trying to set up a development environment for learning Ruby. The
I'm creating an online community and I'm trying to set up a development server.
I am trying to set up a C/C++ development environment on Eclipse (Indigo) running

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.