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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:30:11+00:00 2026-06-03T13:30:11+00:00

I have a mod_rewrite rule working to direct non-existing directories to a php file

  • 0

I have a mod_rewrite rule working to direct non-existing directories to a php file which does a database get based on the $1.

Everything works fine unless the directory does exist, which displays the proper directory, but it also appends the query string when it’s not necessary.

I have been scouring the web for the past few hours and trying different methods with no luck.

Does anyone know how to keep this functioning as-is, but get rid of the query string?

Thanks much.

Here is my code:

RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([0-9a-zA-Z\-]+)/$ $1 [R]
RewriteRule ^([0-9a-zA-Z\-]+)$ product.php?product=$1

What ends up happening is the browser displays the URL as http://domain.com/existing_dir/?product=existing_dir

  • 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-03T13:30:13+00:00Added an answer on June 3, 2026 at 1:30 pm

    try that, it removes / on its own without repeating whole process

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*?)/?$ product.php?product=$1
    

    if You insists on limiting special characters, that would do:

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^([0-9a-zA-Z\-]+?)/?$ product.php?product=$1
    

    + is 1 or more repeatition, * is 0 or more, and +?, *? are modifiers for not hungry matching – it allows /? to match anything

    Additionally in Your example, first RewriteRule is been executed conditionally (when directory does not exists), the second one is executed always (if first whould not break the process) so even if directory exists

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

Sidebar

Related Questions

I have a mod_rewrite rule that will send any subdomain requests to a php
I have this rule: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !index.php RewriteRule ^(.*)$ index.php?req=$1
I have a .htaccess file on a website I'm working on which rewrites urls
I'm trying to get mod_rewrite working with the following URLs: /events.php?view=details&id=$var /events.php?view=edit&id=$var Obviously my
I have a really simple mod-rewrite rule : RewriteRule ^(.*)$ index.php?url=$1 [PT,L] As an
I have a website that employs a generic mod_rewrite rule to push all requests
for some days now I have been trying to make a simple mod_rewrite rule
I have mod_rewrite working on most of my site. Right now I have a
I've been wrestling with a mod_rewrite rule that doesn't seem to be working. Briefly,
I have an .htaccess file using mod_rewrite to redirect URLs from the old website

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.