2015-11-04 98 views
0

我正在做一個URL縮短與基地64編碼我的網址。問題是我的主目錄中還有一堆文件夾。我的目錄看起來是這樣的國防部重寫,忽略目錄,除非URL有一個尾部的斜槓

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

這是重寫規則我用它來捕捉編碼的URL

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

這工作。我的問題來了,當我的系統生成一個url就像這樣http://exampleurlshortener.com/css,在一個理想的情況下,重寫規則將捕獲「css」,並讓我的index.php處理剩下的問題是apache添加了一個尾部斜線,進入css目錄。

所以我需要的是 http://exampleurlshortener/css - >允許的index.php處理請求 http://exampleurlshortener/css/ - >訪問實際的目錄

到目前爲止,我沒有運氣,因爲Apache不斷增加的尾部斜槓

+0

使用'選項-MultiViews' – hjpotter92

+0

沒有運氣,任何想法如何實現? – GbrlMtrz

+0

您是否嘗試在規則中製作/可選項? 'RewriteRule ^([A-Za-z0-9 _ \ - ] {3,8})/?$ index.php?a = $ 1' –

回答

0

您需要關閉DirectorySlash以避免Apache添加尾部斜線。關閉Indexes選項以避免Apache向用戶呈現目錄列表也很重要。

DirectorySlash off 
Options -Indexes 
DirectoryIndex index.php 

RewriteEngine On 

RewriteRule ^([\w-]{3,8})$ index.php?a=$1 [L,QSA]