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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:54:34+00:00 2026-06-05T14:54:34+00:00

These rewrite rules don’t seem to work. Is it just not possible or am

  • 0

These rewrite rules don’t seem to work. Is it just not possible or am I missing something

The problematic rule is the second one, notice the back-reference %1

RewriteCond %{REQUEST_URI} ^/([a-zA-Z\.]+)/.*$ [NC]
RewriteCond %{HTTP_COOKIE} route_controller_%1=([^;]+) [NC]
RewriteRule ^(.*)$ http://example2.com/%1/_/$1 [L]

This is what I am expecting to happen. Given the URL

http://example.com/abc/home

The first rule should store abc in %1
I want the second rule for a cookie called route_controller_abc and if found
Then the third rule would rewite to

http://example2.com/thevalueofthecookie/_/home

But the seconf rule doesn’t seem to be using the %1 back-reference.

Any Ideas?

  • 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-05T14:54:35+00:00Added an answer on June 5, 2026 at 2:54 pm

    The reason for this is that string substitution only occurs in the first parameter on a cond and not on its rexexp. You have to do a hack to simulate parameters in regexps using \1 etc.

    You can also pick up the directory in the rule regexp, since the execution order is rule regexp, cond1, cond2,… rule substitution. eg. ^(*.?)/.*$ for abc/homewill set $1 to abc and $0 to abc/home. Hence I would try something like:

    RewriteCond $1:%{HTTP_COOKIE} ^(.*?):.*\broute_controller_\1=([^;]+) [NC]
    RewriteRule ^(*.?)/.*$        http://example2.com/%2/_/$0            [L]
    

    Note that the controller is now in %2 as %1 is used to bind the directory in the cond regexp.

    Hope this helps and answers your direct Q. Hovever, I would be a little twitchy using unvalidated cookies like this for redirection. If I were doing this I would either tighten the validation of the parameter ([^;]+) or move this to a small PHP redirector script and do the validation there 🙂

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

Sidebar

Related Questions

Hey there my redicret is not working and i don't understand why. My rule
Does anyone can help me converting these rules to [ISAPI_Rewrite]. Thanks. RewriteEngine On RewriteCond
I've got my rewrite rule below and it works: RewriteCond %{HTTP_HOST} ^website\.com$ [NC] RewriteRule
#+FollowSymLinks must be enabled for any rules to work, this is a security #requirement
I have assemled these rules from various sources, do any of you see any
FTR, I'm pretty abysmal at rewrite rules. We've got a number of users who
I have a web.config rewrite rule specified to move all traffic to https. The
I am trying to come up with one single rewrite rule that checks the
My rule looks like this: RewriteRule ^page-parent.*$ http://www.domain.com/new-page/?%{QUERY_STRING} [R=301,L] My issue is that there
Is there any way to rewrite either: flag llvm description: compile via LLVM default

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.