Php Mod Rewrite,忽略目录,除非URL后面有斜杠
我正在为我的url制作一个基于64位编码的url缩短器。问题是我的主目录中还有一堆文件夹。我的目录看起来像这样Php Mod Rewrite,忽略目录,除非URL后面有斜杠,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我正在为我的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 这就行了。当我的系统生成一个类似于http://exampleurlshorte
/
/css
style.css
/handlers
handle_database.php
index.php
.htaccess
这是我用来捕获编码URL的重写规则
RewriteRule ^([A-Za-z0-9_\-]{3,8})$ index.php?a=$1
这就行了。当我的系统生成一个类似于http://exampleurlshortener.com/css
,在理想情况下,重写规则将捕获“css”并让my index.php处理其余内容,问题是apache添加了一个尾随斜杠,它最终进入css目录
所以我需要的是
http://exampleurlshortener/css
->让index.php处理请求
http://exampleurlshortener/css/
->访问实际目录
到目前为止,我还不走运,因为apache一直在添加尾部斜杠,您需要关闭
DirectorySlash
,以避免apache
添加尾部斜杠。关闭索引
选项也很重要,以避免Apache向用户显示目录列表
DirectorySlash off
Options -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^([\w-]{3,8})$ index.php?a=$1 [L,QSA]
使用
Options-MultiViews
运气不好,知道如何实现吗?您是否尝试在规则中设置/optionalRewriteRule^([A-Za-z0-9\-]{3,8})/?$index.php?A=$1
@PanamaJackcss/
目录存在。