2015-06-08 43 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] 
相關問題