dtnpzghys01643322 2015-11-04 15:48
浏览 52

Mod Rewrite,忽略目录,除非URL有一个尾部斜杠

I am making an url shortener with a base 64 encoding for my urls. problem is I also have a bunch of folders inside my main directory. My directory looks something like this

/
  /css
    style.css
  /handlers
    handle_database.php
  index.php
  .htaccess

And this is the rewrite rule I use to capture the encoded urls

RewriteRule ^([A-Za-z0-9_\-]{3,8})$ index.php?a=$1

And that works. my problem comes when my system generates an url that would be like this http://exampleurlshortener.com/css, in an ideal scenario the rewrite rule would capture the "css" and let my index.php handle the rest, problem is apache adds a trailing slash and it ends up getting inside the css directory.

So what I need is that http://exampleurlshortener/css -> lets index.php handle the request http://exampleurlshortener/css/ -> access the actual directory

So far I've had no luck, because apache keeps adding the trailing slash

  • 写回答

1条回答 默认 最新

  • dsutuyxe088689 2015-11-06 10:44
    关注

    You need to turn off DirectorySlash to avoid Apache adding a trailing slash. It is also important to turn off Indexes option to avoid Apache presenting directory listing to users.

    DirectorySlash off
    Options -Indexes
    DirectoryIndex index.php
    
    RewriteEngine On
    
    RewriteRule ^([\w-]{3,8})$ index.php?a=$1 [L,QSA]
    
    评论

报告相同问题?