2015-06-08 46 views
0

新的.htaccess文件(仍无法正常工作,它把我送到localhost/xampp为什么我不能将index.php重定向到域?

RewriteEngine on 
RewriteBase /sample/ 

# set root to index.php 
DirectoryIndex index.php 

# prevent directory listing 
Options -Indexes 

# remove index.php 
RewriteCond %{THE_REQUEST} /index\.php [NC] 
RewriteRule ^(.*)index.php$ $1 [R=301,L,NC] 

# removing extensions 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^.]+)/?$ $1.php [L] 

老的.htaccess文件如下:

RewriteEngine on 

# set root to index.php 
DirectoryIndex index.php 

# prevent directory listing 
Options -Indexes 

# removing extensions 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

# remove index.php 
Options +FollowSymLinks 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://localhost/sample/ [R=301,L] 

域是http://localhost/sample/我已经试过,谷歌给了我很多东西。但他们没有工作。我每次去localhost/sample/index.php它不重定向到localhost/sample/。我还使用了Redirect 301 /index.php /

我试过

RewriteCond %{THE_REQUEST} ^.*/index\.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L] 

但它会将我送到http://localhost/xampp/splash.php

我还是新来的.htaccess所以我真的不知道我做错了什么。我已经尝试了OP给出答案的答案。

+0

我猜你是从'/''到HTTP重定向其他一些规则://本地主机/ XAMPP重定向规则之前/ splash.php' – Quentin

+0

规则匹配任何东西,并且是'[L]',所以在它将被测试之后没有其他规则。 – deceze

+1

加 'RewriteBase /'也 –

回答

0

您可以使用:

# set root to index.php 
DirectoryIndex index.php 
# prevent directory listing 
Options -Indexes 
RewriteEngine on 
RewriteBase /sample/ 

# remove index.php 
RewriteCond %{THE_REQUEST} /index\.php [NC] 
RewriteRule ^(.*)index.php$ $1 [R=301,L,NC] 

# removing extensions 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^.]+)/?$ $1.php [L] 

RewriteBase /sample/是需要做出从当前目录的路径raltive重定向肯定会发生。

+0

'上 RewriteBase /样品RewriteEngine叙述/ #组根到index.php 的DirectoryIndex index.php文件 #防止目录列表 选项-Indexes #index.php文件删除 的RewriteCond%{} THE_REQUEST /索引\ .PHP [NC] 重写规则^(。*)的index.php $ $ 1 [R = 301,L,NC] #去除扩展 的RewriteCond%{REQUEST_FILENAME}!-f 的RewriteCond%{REQUEST_FILENAME} .PHP -f RewriteRule ^([^。] +)/?$ $ 1.php [L]' S结束我到'localhost/xampp' – iamdevlinph

+0

您在清除浏览器缓存后测试了吗?什么是'devsite'和什么是'sample'? 'RewriteBase'必须设置为从站点根目录的相对路径。 – anubhava

+0

对不起。 devsite是样本。 – iamdevlinph

0

使用此:

RewriteEngine On 

# prevent directory listing 
Options -Indexes 

# allows leaving off the extension (.php) in urls 
Options +MultiViews 

# removing extensions 
RewriteCond %{REQUEST_FILENAME} !-f [NC] 
RewriteCond %{REQUEST_URI} !-d 
RewriteRule ^index(\.php)?$ http://localhost/sample [R=301,L] 
相关问题