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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:01:59+00:00 2026-06-07T23:01:59+00:00

I promise I have been looking for hours for the answer here, but it’s

  • 0

I promise I have been looking for hours for the answer here, but it’s still not working. Here’s what I have:

RewriteCond %{HTTP_HOST} ^([^\.]*)\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/%1/ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]

This creates an infinite loop because line two is not matching correctly. However, if I replace %1 in line two with www and go to www.example.com, it works fine. Obviously it no longer works for the other subdomains, but the fact that when I explicitly enter www in line two instead of letting %1 take care of it is strange, because I know the value of %1 is www.

What I’m trying to accomplish is as follows:
I have a domain “example.com”. In the root directory there are several subdirectories, let’s say “dev”, “test” and “www”. Higher up in my htaccess file I have a rule that forces the domain to redirect to “www.example.com” if the subdomain is empty (example.com), w (w.example.com), or ww (ww.example.com), anything else is left alone (dev.example.com, test.example.com). Now this part of the file is supposed to rewrite the request to the correct subdirectory based on the subdomain. So, a request like “dev.example.com/something.jpg” gets rewritten (not redirected) to “dev.example.com/dev/something.jpg”.

The plan here is to be able to create a development and testing environments on the server, without having to recreate an environment on my home server, making sure all the server settings are exactly the same. Also, it could do anything else I wanted it to do I suppose, but that’s the immediate need.

  • 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-07T23:02:01+00:00Added an answer on June 7, 2026 at 11:02 pm

    The problem is that you can’t use a backreference variable in the match expression of a RewriteCond. This is OK:

    # ----------V
    RewriteCond %1 <regex>
    

    But this is not:

    # -------------------------V
    RewriteCond %{REQUEST_URI} %1
    

    Something you could do if you needed to do a match like this is use match backreference \1 to access a match from within the same regular expression. You can then put the %1 back reference in the same left side parameter of RewriteCond and use \1 to match against it. Something like this:

    RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)[^:]*:\1 [NC]
    

    So the %{REQUEST_URI}:%1 bit could look something like this: /foo:subdomain, and ^/([^/]+)[^:]*:\1 won’t match because the expression is looking for foo after the “:” (\1 = “foo”). So the rule gets applied and the URI is now /subdomain/foo, and the second time around, %{REQUEST_URI}:%1 becomes /subdomain/foo:subdomain, this time the regular expression matches because \1 = “subdomain” and the ! makes it so the rule doesn’t get applied.

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

Sidebar

Related Questions

You have to promise not to giggle, but my situation is following: Instead of
I can't find Job in 2.0. Have been replaced by Promise? Promise seems a
I've been looking at MongoDB and I'm fascinated. It appears (although I have to
I have been trying to validate my web page for the last two hours,
This question has been asked before but 1) the user never accepted an answer
I have been a working programmer since the turn of the century and I
Object-relational mapping has been well discussed, including on here. I have experience with a
I have: NSString *promise = @thereAreOtherWorldsThanThese; which I'm trying to transform into the string:
I have an API that returns a promise from a deferred object. The problem
I promise you I am not lying. There is one strange line in this

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.