访问目录时出现htaccess问题

时间:2014-06-19 07:31:49

标签: apache .htaccess mod-rewrite

我的博客链接为http://www.example.com/blog,当我尝试访问它时,它将网址转换为http://www.example.com/blog/?ID=blog,这是不正确的。但是,当我在博客的末尾加上反斜杠时它工作得很好,但我不想在最后反斜杠

我尝试更改htaccess文件中的所有内容但失败了。

这是我的htaccess文件

   Options +FollowSymLinks
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f [OR]
   RewriteCond %{REQUEST_FILENAME} !-d [OR]
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule ^ - [L]
   RewriteRule ^products products.php
   RewriteRule ^websitemap sitemap.php
   RewriteRule ^aboutus aboutus.php
   RewriteRule ^clients clients.php
   RewriteRule ^shoppingcart inq.php
   RewriteRule ^contactus contact.php
   RewriteRule ^finished finished.php
   RewriteRule ^product/([a-zA-Z0-9_-]+)$ product_large.php?ID=$1

   RewriteRule ^([a-zA-Z0-9_-]+)$ category.php?ID=$1
   RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ products.php?ID=$2&MID=$1

   ErrorDocument 404     http://www.example.co.uk/error404.php

   RewriteCond %{HTTP_HOST} ^example.co.uk$
   RewriteRule ^/?$ "http\:\/\/www\.example\.co\.uk\/" [R=301,L]

1 个答案:

答案 0 :(得分:0)

RewriteRule ^ - [L]之后插入此规则以强制使用尾部斜杠:

DirectorySlash On
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(.*?)[^/][?\s]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]

RewriteRule ^blog(/.*)?$ - [L,NC]

# your rest of the rules