我有一个WordPress安装在/var/www/wordpress/和我自己的代码在/var/www/project/
现在出现以下问题:当我尝试访问example.com/client/或example.com/admin/ ,应该链接到/var/www/project/并从那里执行.htaccess + index.php。
我试图在部分成功的Apacheconfiguration中放置一个Alias指令。
Alias /admin/ /var/www/project Alias /client/ /var/www/project
当我访问example.com/client/它可以正常工作,但只要我请求example.com/client/login就会失败,并且File does not exist: /var/www/project/login error。
/var/www/project的.htaccess看起来像
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/(.*)$ index.php?module=$1&task=$2 [L,QSA]
首先:我的pet peeve,从手册中引用.htaccess文件:
如果您有权访问httpd主服务器configuration文件,则应该完全避免使用.htaccess文件。 使用.htaccess文件会降低您的Apache HTTP服务器速度。 您可以包含在.htaccess文件中的任何指令在目录块中设置得更好,因为它具有相同的效果,性能更好。
其次:几乎所有mod_rewrite问题的规范答案都在这里
我不是100%确定,但我认为通过设置RewriteBase /内部redirect,因为它将是example.com/index.php而不是/var/www/project/index.php。 此外,我认为PT标志需要考虑到别名匹配。
你可能想尝试
Alias /admin/ /var/www/project Alias /client/ /var/www/project <Directory /var/www/project> RewriteEngine On RewriteBase / # Do nothing when a file or directory with the requested name exists RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.* - [L] # Use the request URL to select the correct module and task RewriteRule ^/([^/]+)/(.*)$ /$1/index.php?module=$1&task=$2 [PT,L,QSA] </Directory>
Alias的文档显示这是预期的行为。 别名在别名path之后追加任何追踪path。
我想你想要的是通过别名扔掉额外的path信息
AliasMatch /(admin|client)/.* /var/www/project
这应该将请求发送到/ var / www / project,同时保持原始请求的URLpath不受RewriteRule处理。