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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:21:24+00:00 2026-06-02T02:21:24+00:00

I am using mod_rewrite to pass identifiers to my web app in the form:

  • 0

I am using mod_rewrite to pass identifiers to my web app in the form:

http://clipi.ca/1W

I am identifying these with a simple regex:

RewriteCond %{REQUEST_URI} ^/([0-9a-zA-Z]+)$
RewriteRule ^(.*)$ /index.php?urlid=%1 [L,QSA]

…which works fine in most cases. However I noticed that when the identifier is the name of a directory, the rewrite is failing and Apache is returning a directory index!

How can I stop this behavior and have the rewrite rule apply to directories as well? (Note that as soon as an actual file inside a directory is referenced, the rewrite condition fails and it is not a problem.)

  • 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-02T02:21:26+00:00Added an answer on June 2, 2026 at 2:21 am

    I think I may have figured it out myself: Apparently, Apache will append a trailing slash to requests that map to directories on the filesystem before it applies any rewrite rules. That’s kind of silly, imo, but by adding an optional trailing slash to my conditional regex:

    RewriteCond %{REQUEST_URI} ^/([0-9a-zA-Z]+)/?$
    

    …it seems to be working!

    Still, the ideal solution would be to get Apache to not append that trailing slash to begin with. If anyone knows how to do that, post it here and I’ll give you the answer credit.

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

Sidebar

Related Questions

Noticed Apache strange behavior. I'm using mod_rewrite to redirect every RewriteCond %{REQUEST_URI} !^.*css|gif|js|png$ RewriteRule
I am currently using mod_rewrite to do an internal redirection RewriteCond %{REQUEST_URI} ^/pattern$ RewriteRUle
I'm setting up some simple url rewriting rules using mod_rewrite and a .htacces file,
HI guys. Im using mod_rewrite to do some redirects on a web site. I
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'm using mod_rewrite to rewrite pretty URLs to a form supported by a Spring
I want to redirect the following url: http://abc.com/colleges/first.php to http://abc.com/first.php using mod_rewrite and .htaccess
Is there a way to rewrite an URL like http://mydomain.com/getProduct.php?id=1&mode=simple in http://mydomain.com/products/1/simple using mod_rewrite
Hay, I'm using mod_rewrite with apache, and want URLS from http://www.DOMAN.com/course/course-a/ to actually serve
Using mod_rewrite, how could I turn URLs that follow this pattern: http://example.com/index.php?id=14 Into this

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.