2017-10-16 161 views
0

我嘗試將index.php和系統頁面(如404.php,403.php等)重定向到它們各自的.html頁面(index.html,404.html,403)。 HTML等)在ROOT目錄中。Htaccess將php文件重定向到根目錄中的html

問題是,在Stackoverflow上提供的建議解決方案似乎不適用於我的情況。由於技術要求,PHP文件必須保留在根目錄中。

規則在.htaccess

RewriteOptions inherit 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME}/index.html !-f 
RewriteCond %{REQUEST_FILENAME}/index.php !-f 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule . index.php [L] 

</IfModule> 
# -- concrete5 urls end -- 

<IfModule mod_headers.c>  
    Header set Access-Control-Allow-Origin * 
</IfModule> 
#Header set Access-Control-Allow-Origin * 

回答

1

在你的主目錄.htaccess文件試試這個代碼:

RewriteEngine On 
RewriteRule ^(index|404|403)\.php$ /$1.html [L,R=302] 

上面的代碼會重定向只提到了在根目錄下的網頁,如果要添加子目錄對其中的任何一個,只需將其更改爲像sub/indexsub/404等等。

我適合是好的,改變302301獲得永久重定向

+0

這部分的工作。所有內容現在都重定向到index.html。但是,如果我訪問php相關子目錄(根/文件夾)中的文件夾,它也會重定向到index.html中的根目錄,而不是該子目錄中的index.php。 – Alex

+0

我確定它只適用於根目錄,但你可能在子目錄中有其他規則,請稍等我修改它 –

+0

它應該只在根目錄下工作,讓我知道你是否有.htaccess中的子文件夾或子文件夾中的任何規則 –

相關問題