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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:53:32+00:00 2026-05-15T07:53:32+00:00

I use mod_rewrite/.htaccess for pretty URLs. I forward all the requests to my index.php,

  • 0

I use mod_rewrite/.htaccess for pretty URLs. I forward all the requests to my index.php, like this:

RewriteRule ^/?([a-zA-Z0-9/-]+)/?$ /index.php [NC,L]

The index.php then handles the requests.

I’m also using this condition/rule to eliminate trailing slashes (or rather rewrite them to the URL without a trailing slash, with a 301 redirect; I’m doing this to avoid duplicate content and because I like no trailing slashes better):

RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

This works well, except that I now get an infinite loop when trying to access a (real) directory (the rewrite rule removes the trailing slash, the server adds it again, …).

I solved this by setting the DirectorySlash directive to Off:

DirectorySlash Off

I don’t know how good this solution is, I don’t feel too confident about it tbh.

Anyway, what I’d like to do is completely ignore “real” files and directories, since I don’t need them and I only use pretty URLs with “virtual” files/directories anyway. This would allow me to avoid the DirectorySlash workaround/hack too.

Is this possible?

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-05-15T07:53:33+00:00Added an answer on May 15, 2026 at 7:53 am

    This is because you overwrite the file and folder request, too. You should add a new RewriteCond before the rule, which tells the server it should only rewrite non-existing items.

    The code:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    

    I hope this helps.

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

Sidebar

Related Questions

I'd like to use mod_rewrite to make pretty URLs, but have a single version
I use .htaccess Mod Rewrite to send the URL to index.php, which then parses
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
In php I have a script, that I use mod_rewrite to redirect all calls
Currently I have a url like this http://<client_name>.website.com/index.php?function_name&cat=32 I want to set things up
If I use mod_rewrite to control all my 301 redirects, does this happen before
I'm not sure if this is possible but I want to use mod_rewrite like
I have an web application in PHP with urls like this: https://www.domain.com/?mod=test&act=view My problem
I am trying to use PHP mod_rewrite to alter some URLs. As a test,
As the title says, how can I use .htaccess and mod_rewrite to change 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.