一两天后,我仍在与 Mod Rewrite 战斗。似乎我 60% 的开发时间都花在了与服务器的战斗上。
我当前的 URL 结构是所有http://example.com/xyz和http://example.com/xyz/abc都应该由 index.php 处理。问题是我有一个http://example.com/admin/部分,这是一个真实的目录,我需要通过 HTTP 请求访问它(它是 CMS 目录)
当我尝试浏览到 CMS http://example.com/admin/时,它会将我的 URL 更改为http://example.com/admin/?n=admin并返回 404。我的 index.php 正在接收 n =admin 作为它的论点。
我无法理解的是为什么这两个条件被忽略了:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^admin(?:\/)?$
以及为什么我将重定向到http://example.com/admin/?n=admin(而不是仅仅停留在http://example.com/admin/。
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^admin(?:\/)?$
# allow access to certain subdirectories.
RewriteRule ^admin(?:\/)?$ /admin/ [L,NC]
# redirect all old URLs to new pages (or 404 sitemap page if no analog?).
RewriteRule ^company/about(?:\/)?$ /company [R=301,L,NC]
# catch any others and try to serve them right
RewriteRule ^/?(.+).html$ /$1 [R=301,L]
RewriteRule ^/?([0-9]+)(?:\/)?$ /index.php?p=$1 [L]
RewriteRule ^/?([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$1 [L]
RewriteRule ^/?([-a-zA-Z0-9_+]+)/([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$2 [L]
任何人都可以提供任何想法或指出 .htaccess 中的任何缺陷吗?