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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:46:56+00:00 2026-06-13T04:46:56+00:00

Question: Is it possible to clear the %{QUERY_STRING} without breaking any functionality of what

  • 0

Question:

Is it possible to clear the %{QUERY_STRING} without breaking any functionality of what I’ve accomplished in my .htaccess file.

I want to prevent users from adding ?foo=bar to the end of the url overwriting any predefined $_GET vars

(external re_write) Example:

From: example.com/foo/bar/hello/world?test=blah

To: example.com/foo/bar/hello/world

So far I have been able to accomplish this (internally):

From: example.com/foo/bar/hello/world

To: example.com/index.php?foo=bar&hello=world

.htaccess

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s.+\.(?:html?|php|aspx?) [NC]
RewriteRule ^(.+)\.php$ /$1 [R=301,L,NC]

# To externally redirect /dir/index to /dir/
RewriteCond %{THE_REQUEST} ^GET\s((.+)?(\/)?)?(index) [NC]
RewriteRule ^(([^/]+/)*)index$ /$1 [R=301,L,NC]

# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [L]

# Prevent Rewrite on existing directories, files, and links
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L] #^ - [L]

# To internally rewrite directories as query string
RewriteRule ^([^/=]+)=([^/]*)(/(.+))?\/?$ /$4?$1=$2 [N,QSA]
RewriteRule ^([^/=]+)/([^/=]+)(/(.+))?\/?$ /$4?$1=$2 [N,QSA]
RewriteRule ^([^/=]+)(/(.+))?\/?$ /$3?$1 [N,QSA]

What I’ve tried:

#if there is a query string
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule (.*) $1? [R=301,L] #remove query string

–

#if there is a query string
RewriteCond %{QUERY_STRING} !=""
RewriteRule (.*) $1? [R=301,L] #remove query string

–

#if there is a query string
RewriteCond %{QUERY_STRING} !=""
RewriteRule ^(.*)$ $1? [R=301,L] #remove query string

I read somewhere, and experienced it, that applying the above breaks anything I’ve already accomplished. Completely clearing the whole url if they are masked $_GET vars. Even crashes apache 0.o (forgive me for any silly regex or .htaccess code, they’re aren’t my strong suite and most of it was snippets I found on SO)

is this possible? something I’m doing wrong?

thanks

  • 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-13T04:46:57+00:00Added an answer on June 13, 2026 at 4:46 am

    Try:

    RewriteCond %{THE_REQUEST} \?[^\ ]+
    RewriteRule (.*) /$1? [R=301,L] #remove query string
    

    You need to match against the actual request because you’re building a query string with these rules:

    # To internally rewrite directories as query string
    RewriteRule ^([^/=]+)=([^/]*)(/(.+))?\/?$ /$4?$1=$2 [N,QSA]
    RewriteRule ^([^/=]+)/([^/=]+)(/(.+))?\/?$ /$4?$1=$2 [N,QSA]
    RewriteRule ^([^/=]+)(/(.+))?\/?$ /$3?$1 [N,QSA]
    

    When these rules loop around, the %{QUERY_STRING} variable will have stuff in it and your rules will clobber them. If you match against the actual request, your rewrites won’t get affected.

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

Sidebar

Related Questions

Possible Duplicate / a more recent/less clear question Branch from a previous commit using
I think the question title is clear enough: is is possible to stable_sort() a
Question: Is it possible to compile a program on linux using a .dll file?
THE QUESTION Is it possible to run one tab from a different Activity or
Possible Duplicate: MySQL query that computes partial sums ok, the question is not clear
First I want to make clear this is not a simple LIMIT x,y question.
I am trying to make this question sound as clear as possible. Basically, I
Is the above question possible? The effect I'm trying to achieve is similar to
Question Is it possible to stop a Message Driven Bean (programmatically), so that it
Question: Is is possible, with regex, to match a word that contains the same

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.