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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:59:47+00:00 2026-06-09T04:59:47+00:00

I am using mod_rewrite to send queries to PHP for handling in a CMS.

  • 0

I am using mod_rewrite to send queries to PHP for handling in a CMS. My problem: if the query is the name of a directory, the query that gets sent to PHP is added to the URL.

Here is the code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /process.php\?query=$1 [QSA,NC,L]

So if the user types in

http://example.com/lolcats

mod_rewrite silently redirects to

http://example.com/process.php?query=lolcats

which is great. But if lolcats is a directory, mod_rewrite redirects (NOT silently) to

http://example.com/lolcats/?query=lolcats

adding the query to the end of the original request. Apache still serves the PHP output, but it changes the URL in the user’s address bar.

So I need to stop the query from being added to the request even if the query is the name of a directory.

  • 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-09T04:59:48+00:00Added an answer on June 9, 2026 at 4:59 am

    This is a DirectorySlash issue, where apache redirects with a trailing slash when you try to access a directory.

    You can either turn DirectorySlash Off (noting that there is a security warning concerning turning this off), or try to have mod_rewrite handle it preemptively with something like:

    # Above your existing rules
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)$ /$1/ [R=301,L]
    
    # and small modification to your existing rule to handle trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)/$ /process.php\?query=$1 [QSA,NC,L]
    

    THough if you are routing all existing directories through process.php, the security warning can probably be ignored.

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

Sidebar

Related Questions

Using mod_rewrite, how could I turn URLs that follow this pattern: http://example.com/index.php?id=14 Into this
I'm using mod_rewrite to rewrite .html to .php. RewriteRule ^([0-9a-zA-Z-_]+)\.html$ index.php?p=$1 [L] But, I'm
I am using mod_rewrite to put a category name in the URL, like locahost/categoryName
I'm using mod_rewrite to map my old directory structure to a new one. I
I'm trying to hide actual sub-directory from url path using mod_rewrite. The folder actual
I'm trying to change all http://www.mysite.com/filename.php files to show as http://www.mysite.com/filename/ using mod_rewrite, but
I am using mod_rewrite in my PHP framework to redirect user-friendly links to one
How using mod_rewrite could i manipulate the query string variable? e.g. i want the
Noob in mod_rewrite here...I'm developing a new site and using mod_rewrite. The problem is,
I'm using mod rewrite to access my PHP files in the root directory 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.