2012-08-28 66 views
0

我很不幸被困在这里。 我做了一个干净的网址htaccess重定向。但每当我有对应的现有目录的路径,反斜线将被添加这是很烦人的,在我的脚本生成的错误。阿帕奇国防部重写,DirectorySlash关根修复(中看到指数)

所以我改变了DirectorySlash选项设置为关闭,并将其固定美丽我的问题。是的,我知道安全警告和停用索引。

现在我最大的问题是如下:如果输入的路径,网站没有结尾的斜线,因为REQUEST_URI是空的,我不能重定向到我的index.php。

所以, “www.my-website.com/” 会工作,但 “www.my-website.com” 不会。

我心想:“嗯,我会只是检测是否该要求是空的”。什么都没发生。或者mayble只关闭子文件夹的directoryslash? 搜索后几个小时,我发现下面做工作,但意味着我不得不写的网址硬和真的不最佳

Options +FollowSymlinks 
RewriteEngine on 
    #prevent from weird bug if path is a directory 
DirectorySlash Off 

    # add the trailing slash to root directory 
    # THIS IS WHERE I NEED A VARIABLE PATH THAT I DON'T NEED TO CHANGE MANUALY 
RedirectMatch ^/?([^\.\/]+)$ http://my-fixed-url.com/$1/ 

    # Don't show directory indexes (the listing of files) 
Options -Indexes -MultiViews 

    # as long is it isn't an existing file 
RewriteCond %{REQUEST_FILENAME} !-f 

    # Then redirect to index.php with the param "path" set to the url 
RewriteRule ^([a-zA-Z0-9\_\-\/\.]+)$ index.php?path=$1 [QSA] 

任何帮助表示深深的感谢!

回答

0

只需将+更改为*即可匹配此“空”网址。所以:

RewriteRule ^([a-zA-Z0-9\_\-\/\.]*)$ index.php?path=$1 [QSA] 
+0

不,不工作 – rwt

+0

尽量只在结尾加上这条规则:'重写规则^ $ index.php文件路径= /' – Gerben

+0

没有,绝对没有。就像提醒一样,DirectorySlash如果关闭 – rwt

相关问题