【发布时间】:2015-11-04 15:48:26
【问题描述】:
我正在为我的网址制作一个使用 base 64 编码的网址缩短器。问题是我的主目录中也有一堆文件夹。我的目录看起来像这样
/
/css
style.css
/handlers
handle_database.php
index.php
.htaccess
这是我用来捕获编码网址的重写规则
RewriteRule ^([A-Za-z0-9_\-]{3,8})$ index.php?a=$1
这行得通。当我的系统生成一个类似于http://exampleurlshortener.com/css 的 url 时,我的问题就出现了,在理想情况下,重写规则将捕获“css”并让我的 index.php 处理其余部分,问题是 apache 添加了一个斜杠,它最终进入 css 目录。
所以我需要的是
http://exampleurlshortener/css -> 让 index.php 处理请求
http://exampleurlshortener/css/ -> 访问实际目录
到目前为止,我没有运气,因为 apache 不断添加尾部斜杠
【问题讨论】:
-
使用
Options -MultiViews -
运气不好,知道如何实现吗?
-
您是否尝试在规则中设置 / 可选?
RewriteRule ^([A-Za-z0-9_\-]{3,8})/?$ index.php?a=$1 -
@PanamaJack
css/目录存在。
标签: php apache .htaccess mod-rewrite