指向没有扩展名到根的网址

时间:2014-09-16 18:17:59

标签: php .htaccess redirect

我目前设置了htaccess文件,以便在有人输入www.example.co.uk/index.php时重定向到www.example.co.uk/

但是,如果有人输入www.example.co.uk/index,则网址会保持为www.example.co.uk/index

有没有办法可以将其重定向到根并隐藏/index部分?

htaccess代码目前如下(我遗漏了大部分301重定向)

ErrorDocument 404 /notfound.php

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.w-co\.co.uk$
RewriteRule (.*) http://www.w-co.co.uk/$1 [R=301,L]


Options +FollowSymLinks 
# Redirect index in any directory to root of that directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.[^\ ]*\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(php|html?)$ http://www.w-co.co.uk/$1? [R=301,L]

AddType video/mp4 .mp4
AddType video/ogg .ogv
AddType video/webm .webm

Redirect 301 /%20built-up-lettering.php  http://www.w-co.co.uk/built-up-lettering.php
Redirect 301 /">light http://www.w-co.co.uk/light_boxes.php

1 个答案:

答案 0 :(得分:0)

为您的.htaccess添加重写规则:

^www.example.co.uk/index$

这应该涵盖它。