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

The Archive Base Latest Questions

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

I found a Question similar to my problem( Regular Expression For URL Query )

  • 0

I found a Question similar to my problem(Regular Expression For URL Query) but could not make my problem to be resolved.

So I am having trouble with Regular Expressions in HTACCESS.

So what I have in my website is :

ROOT : (my web root is in a sub folder ‘sites’)

/sites/index.php and other files

/sites/sites/sample_folder_name/

Now what I would like to do is to ReWrite URL :

/sites/sites/sample_folder_name/file_name.php

to :

/sites/file_name.php?siteredirect=sample_folder_name

Remember :
If the URL contains any Request Parameters, then those must also be rewrited, i.e :

Example :

/sites/sites/sample_folder_name/file_name.php?cat_id=1&user=2

to :

/sites/file_name.php?cat_id=1&user=2&siteredirect=sample_folder_name

The parameters are supposed to be unknown instead of user and cat_id. It could be any parameters. Means that whatever is written after .php should also come in URL.

Means :

/sites/sites/sample_folder_name/file_name.php?if_any_parameters

then :

/sites/file_name.php?if_any_parameters&siteredirect=sample_folder_name

otherwise :

/sites/file_name.php?siteredirect=sample_folder_name

Currently, the rewrite is working great but I am not able to make them work with parameters.

What I have in my HTACCESS right now :

RewriteRule ^sites\/([0-9A-Za-z_]+)\/([0-9A-Za-z_]+)\.php(.*)$ $2.php(?(?=$3)$3&)siteredirect=$1 [L]
RewriteRule ^sites\/([0-9A-Za-z_]+)\/$ index.php?siteredirect=$1 [L]

After this, it is giving me a 404.

Please Help… Where am I doing it wrong !

  • 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-27T19:44:02+00:00Added an answer on May 27, 2026 at 7:44 pm

    You need the QSA flag (Query String Append):

    RewriteRule ^sites(/sites/[^/]+)/([^/]+)$ $1?siteredirect=$2 [QSA]
    

    What’s more, invert your rules: you won’t have to use L

    Also, consider using <Location> directives, it will make your job easier:

    <Location "/site/site">
        #rules here
    </Location>
    
    <LocationMatch "^/site/(?!site/)">
        #rules here
    </Location>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found a similar question, but the accepted answer is not what I want:
Just that. I found a similar question here : c# console, Console.Clear problem but
First of all, I've found a similar question but it does not do the
I've found a similar question on stack overflow, but it didn't really answer the
I've found a similar question here , but I'm looking for more general solutions.
I can't resolve this issue, I found a similar question here but: setting the
I found this question but it was only similar and, more importantly, dated by
I've looked around on stackoverflow for a similar question, but haven't found exactly what
I found a couple questions similar to this, but not specifically for .NET projects,
While I found similar question I didn't find an answer to my problem When

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.