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

  • Home
  • SEARCH
  • 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 6167759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:34:03+00:00 2026-05-23T22:34:03+00:00

I currently have the working Mod Rewrite Regex: RewriteEngine On RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule

  • 0

I currently have the working Mod Rewrite Regex:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*/)?((?:cmd)[^/]*)/((?!(?:cmd)[.+]*)(.+)) $1?$2=$3&%1 [L]

That regex takes the following URL and transforms it into the URL immediately below:

www.site.com/cmd1/param/cmd2/param2/stillparam2 and turn it into www.site.com/index.php?cmd1=param&cmd2=param2/stillparam2

That works fine, but I would also like to create another negative lookahead assertion to ensure that a URL block – ie a /texthere/ param – doesn’t include an underscore. An invalid string might look like: www.test.com/cmd/thing/getparam_valuehere; the regex should parse the cmd/thing as a key and value pair and ignore the rest of the string. I would then also write another RewriteRule to have the block of the URL with the underscore in it added as another URL parameter. The following URL translation would occur:

www.test.com/cmd/param1/cmd2/directory/param2/sortorder_5
www.test.com?cmd=param1&cmd2=directory/param2&sortorder=5

Please let me know if I have not been clear enough. Any help would be great.

NB: I have tried using a negative lookahead nested inside the one already present – (?!(?!)) – and have tried using an | on two negative lookaheads, but neither solutions worked. I thought that perhaps something else was more fundamentally wrong?

Thanks all.

Edit: I have also tried the following – which I really thought would work (but obviously, didn’t!)

RewriteRule ^(.*/)?((?:cmd)[^/]*)/((?!(?:cmd)[.+]*)(?![.+]*(?:_)[.+]*)(.+)) $1?$2=$3&%1 [L]

That does the following:

www.test.com/cmd/param1/sortorder_1/ translates to
www.test.com?cmd=param1/sortorder_1/

When it should instead become: www.test.com?cmd=param1&sortorder=2/. The rule to translate /sortorder_2/ into&sortorder=2 has not yet been created, but you can hopefully see what I mean).

  • 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-23T22:34:04+00:00Added an answer on May 23, 2026 at 10:34 pm

    After about four days of experimenting, I ended up with a somewhat different solution than I had originally expected to find. I simply removed all the actual URL manipulation to my index.php file and routed all requests through there. Here is my (much cleaner) .htaccess file:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{QUERY_STRING} (.*)
    RewriteRule (.*) index.php?path=$1 [QSA,L]
    

    and here is the block of code I used to parse the entered URL:

    preg_match_all(‘|/([A-Za-z0-9]+)((?!/)[A-Za-z0-9-.]*)|’, $_GET[‘path’], $matches);

            // Remove all '$_GET' parameters from the actual $_GET superglobal:
            foreach($matches[0] as $k => $v) {
                $search = '/' . substr($v, 1);
                $_GET['path'] = str_replace($search, '', $_GET['path'], $count);
            }
    
            // Add $_GET params to URL args
            for ($i = 0; $i < count($matches[1]); $i++) {
                self::$get_arguments[$matches[1][$i]] = $matches[2][$i];
            }
    
            // Retrieve all 'cmd' properties from the URL and create an array with them:
            preg_match_all('~(cmd[0-9]*)/(.+?)(?=(?:cmd)|(?:\z))~', $_GET['path'], $matches);
    
            if (isset($matches[1][0])) {
                return self::$url_arguments = array_combine($matches[1], $matches[2]);
    

    On a URL like this:

    http://localhost/frame_with_cms/frame/www/cmd/one/cmd2/two/cmd3/three/cmd4/four/getparam_valuepart1_valuepart2/cmd5/five/
    

    It successfully produces these separate arrays which I then use to handle requests:

    Array
    (
        [getparam] => valuepart1_valuepart2
    )
    Array
    (
        [cmd] => one/
        [cmd2] => two/
        [cmd3] => three/
        [cmd4] => four/
        [cmd5] => five/
    )
    

    Thanks to all who took the time to read and reply.

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

Sidebar

Related Questions

I have a project that I'm currently working on but it currently only supports
I have a site that I am currently working on in ASP.NET 2.0 using
I have the following problem using subversion: I'm currently working on the trunk of
I'm working through Practical Web 2.0 Appications currently and have hit a bit of
I am working on Conway's Game of Life currently and have gotten stuck. My
I have recently started using Vim as my text editor and am currently working
I am currently working on my first website. I have no idea where to
I'm currently working on project with Haskell, and have found myself some trouble. I'm
In the project I am currently working on, we have the need to develop
I'm currently working on an in-house CMS and have come to a bit of

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.