【发布时间】:2015-07-25 23:06:37
【问题描述】:
我想使用 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/$1 [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.*?)/?$ $1.html [L]
Options -Indexes
【问题讨论】:
标签: regex apache .htaccess mod-rewrite url-rewriting