2016-10-07 53 views
0

我正在使用htacess文件從我的網頁中刪除.php擴展名。 但是,我有一個名爲images.php的頁面和一個名爲images(都在根目錄中)的目錄。重定向使用htaccess不工作

因此,當從圖像網頁中刪除.php擴展名時,該網站將重定向到圖像目錄。

我試着從image.php重命名圖像文件imageone.php,然後用htacess重定向,但問題仍然存在

我可以以任何方式解決這個?

# Remove .php 
    <IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule .* $0.php 

    #browser requests PHP 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php 
    RewriteRule ^/?(.*)\.php$ /$1 [L,R=301] 

    # check to see if the request is for a PHP file: 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^/?(.*)$ /$1.php [L] 
    </IfModule> 



    Redirect 301 /images.php http://www.thewebsite.com/imagesone.php 
+1

的問題是你第一次重寫PHP文件的擴展名,因此請求/images.php最終變爲/圖片然後轉換到/ images /目錄 – Derek

+0

謝謝德里克,是的,我認爲...我可以改變順序嗎?我試圖把上面的重定向.PHP截斷規則,但得到了同樣的問題 – stckpete

+0

嘗試重定向移動到mod_rewrite的 – Derek

回答

1

在您的評論行browser requests PHP之前,您忘記了#

# browser requests PHP 
+0

感謝的頂部,即只是一個錯字 – stckpete

0

避免在此混合順序Redirectmod_rewrite,有你的規則:

RewriteEngine On 

RewriteRule ^/?images\.php$ http://www.thewebsite.com/imagesone.php [L,NC,R=301] 

# browser requests PHP 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php 
RewriteRule ^/?(.+)\.php$ /$1 [L,R=301,NC] 

# internally add .php to requests 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 
+0

@stckpete:這是否工作? – anubhava