目標:要使瀏覽器重寫爲file-name.php,如果存在;否則返回文件name.html - 訪問者是否已經輸入的網址爲下列任何一個:.htaccess將文件uri重寫爲file-name.html或file-name.php - 無論哪一個存在
http://mydomain.com/file-name
http://mydomain.com/file-name.html
http://mydomain.com/file-name.php
曾與下面的規則很好的成功在我的.htaccess文件中:
# REWRITE FILE URI TO file.php IF EXISTS
Options Indexes +FollowSymLinks +MultiViews
Options +ExecCGI
RewriteEngine on
RewriteBase/
# parse out basename, but remember the fact
RewriteRule ^(.*).html$ $1 [C,E=WasHTML:yes]
# rewrite to document.php if exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1]
# else reverse the previous basename cutout
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.html
不過,我已經在根目錄安裝了WP,並與原有的網站一起安裝,這些規則不再有效。
是什麼工作:file-name
被改寫要麼file-name.html
或file-name.php
- 無論文件存在。
什麼行不通:file-name.html
即使沒有file-name.html
和file-name.php
有沒有改寫爲file-name.php
。另外,當沒有file-name.php
時,file-name.php
不被重寫爲file-name.html
,但是存在file-name.html
。
整個的.htaccess因爲它現在是:
# BEGIN WP MULTISITE RULES
RewriteEngine On
RewriteBase/
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule^- [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WP MULTISITE RULES
# REWRITE FILE URI TO file.php IF EXISTS
Options Indexes +FollowSymLinks +MultiViews
Options +ExecCGI
RewriteEngine on
RewriteBase/
# parse out basename, but remember the fact
RewriteRule ^(.*).html$ $1 [C,E=WasHTML:yes]
# rewrite to document.phtml if exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1]
# else reverse the previous basename cutout
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.html
有何意見?
是的,我移動了WP上面的規則,它再次工作。大多。也就是說,'file-name'返回'file-name.html'或'file-name.php' - 無論哪個存在,'file-name.html'將返回'file-name.php'(如果存在)。但'file-name.php'如果只有'file-name.html'而沒有'file-name.php'則返回404。在這種情況下,什麼會導致'file-name.php'重寫爲'file-name.html'? –