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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:54:21+00:00 2026-05-14T20:54:21+00:00

I have a PHP-based web app that I’m trying to apply Apache’s mod_rewrite to.

  • 0

I have a PHP-based web app that I’m trying to apply Apache’s mod_rewrite to.

Original URLs are of the form:
http://example.com/index.php?page=home&x=5

And I’d like to transform these into:
http://example.com/home?x=5

Note that while rewriting the page name, I’m also effectively “moving” the question mark. When I try to do this, Apache happily performs this translation:

RewriteRule ^/([a-z]+)\?(.+)$ /index.php?page=$1&$2  [NC,L]

But it messes up the $_GET variables in PHP. For example, a call to http://example.com/home?x=88 yields only one $_GET variable (page => home). Where did x => 88 go? However, when I change my rule to use an ampersand rather than a question mark:

RewriteRule ^/([a-z]+)&(.+)$ /index.php?page=$1&$2  [NC,L]

a call like http://example.com/home&x=88 will work just as I’d expect it to (i.e. both the page and x $_GET variables are set appropriately).

The difference is minimal I know, but I’d like my URL variables to “start” with a question mark, if it’s possible. I’m sure this reflects my own misunderstanding of how mod_rewrite redirects interact with PHP, but it seems like I should be able to do this (one way or another).

Thanks in advance!
Cheers,
-Chris

  • 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-14T20:54:21+00:00Added an answer on May 14, 2026 at 8:54 pm

    Try this:.

    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteRule ^/([a-z]+)(?:$|\?(?:.+)) /index.php?page=$1 [NC,L,B,QSA,NE]
    

    B escapes the backreference (shouldn’t be necessary since it is matching [a-z]+, but in case you want to extend it later, it might be useful).

    EDIT: added RewriteCond.
    EDIT 2: QSA takes care of adding the ampersand.

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

Sidebar

Related Questions

I have a php based web app that on a user entering a value,
I'm working on a class-based php web app. I have some places where objects
I have a complex input form within a PHP based web application. To structure
I have an existing large(ish) PHP web app (using Apache and MySQL) which now
Heres my problem, I'm web developer and I have a web based script(PHP/CURL/HTML/JS) that
I have a PHP-based web application that monitors the status of a process and
I have an existing web app that allows users to rate items based on
I have a PHP script that creates other PHP files based on user input.
I am creating a very large PHP MVC-based site that will have a large
I'd like to have a page in php that normally displays information based on

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.