Url 仅当文件夹存在时才重定向到该文件夹
Url redirect to folder only if it exist
我想使用 Url 重写来转换它:
到
- 如果 mypage.html 或 .php 存在于根重定向中,请使用它。 http://test.com/mypage.php
- 否则,如果根目录中不存在 mypage.html 或 .php,请检查 /pages/ 文件夹(如果存在)。 http://test.com/pages/mypage.php
- 否则,如果它不存在于根目录和 /pages/ 文件夹中,则只显示 404 错误页面 http://test.com/404.php
我已经有了 ErrorDocument 404 的一些代码,www。移除并移除 .php 和 .html 扩展名
ErrorDocument 404 http://test.net/404
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.test.net [NC]
RewriteRule ^(.*) http://test.net/ [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/.php -f
RewriteRule ^(.*?)/?$ .php [L]
RewriteCond %{DOCUMENT_ROOT}/.html -f
RewriteRule ^(.*?)/?$ .html [L]
Options -Indexes
您可以使用:
ErrorDocument 404 /404.php
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(test\.net)$ [NC]
RewriteRule ^(.*) http://%1/ [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/.php -f
RewriteRule ^(.+?)/?$ .php [L]
RewriteCond %{DOCUMENT_ROOT}/.html -f
RewriteRule ^(.+?)/?$ .html [L]
RewriteCond %{DOCUMENT_ROOT}/pages/.php -f
RewriteRule ^(.+?)/?$ pages/.php [L]
我想使用 Url 重写来转换它:
到
- 如果 mypage.html 或 .php 存在于根重定向中,请使用它。 http://test.com/mypage.php
- 否则,如果根目录中不存在 mypage.html 或 .php,请检查 /pages/ 文件夹(如果存在)。 http://test.com/pages/mypage.php
- 否则,如果它不存在于根目录和 /pages/ 文件夹中,则只显示 404 错误页面 http://test.com/404.php
我已经有了 ErrorDocument 404 的一些代码,www。移除并移除 .php 和 .html 扩展名
ErrorDocument 404 http://test.net/404
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.test.net [NC]
RewriteRule ^(.*) http://test.net/ [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/.php -f
RewriteRule ^(.*?)/?$ .php [L]
RewriteCond %{DOCUMENT_ROOT}/.html -f
RewriteRule ^(.*?)/?$ .html [L]
Options -Indexes
您可以使用:
ErrorDocument 404 /404.php
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(test\.net)$ [NC]
RewriteRule ^(.*) http://%1/ [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/.php -f
RewriteRule ^(.+?)/?$ .php [L]
RewriteCond %{DOCUMENT_ROOT}/.html -f
RewriteRule ^(.+?)/?$ .html [L]
RewriteCond %{DOCUMENT_ROOT}/pages/.php -f
RewriteRule ^(.+?)/?$ pages/.php [L]