【发布时间】:2015-03-17 05:59:42
【问题描述】:
我是 .htaccess 相关内容的新手,虽然我不是 linux 或 php 开发。我遇到了一个让我发疯的错误。
我启用了重写和 userdir 模块的 apache。我的 mod_userdir.conf 看起来像这样
<IfModule mod_userdir.c>
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS PROPFIND>
Require all granted
</Limit>
<LimitExcept GET POST OPTIONS PROPFIND>
Require all denied
</LimitExcept>
</Directory>
</IfModule>
我正在 $HOME/public_html/mywebsite 中构建一个网页,其中我有一个带有代码的 .htaccess
Options +FollowSymLinks
RewriteEngine On
#RewriteRule ^images/ - [L]
#RewriteRule ^css/ - [L]
#RewriteRule ^js/ - [L]
RewriteRule ^favicon.ico - [L]
RewriteRule ^(images|css|js|classes)($|/) - [L]
RewriteRule ^PayPal classes/paypal/initPP.php [L,QSA]
RewriteRule ^PDF MakePDF.php [L,QSA]
RewriteRule ^([-_0-9a-zA-Z:/]*)$ index.php?PageCall=$1 [L,QSA]
# 400 - Bad request
ErrorDocument 400 /index.php?error=400
# 401 - Authorization Required
ErrorDocument 401 /index.php?error=401
# 403 - Forbidden
ErrorDocument 403 /index.php?error=403
# 404 - Wrong page
ErrorDocument 404 /index.php?error=404
# 500 - Internal Server Error
ErrorDocument 500 /index.php?error=500
我的问题是每次访问http://localhost/~user/mywebsite 都会返回一个 404 页面。我猜是重写问题,因为,当一个评论
RewriteRule ^([-_0-9a-zA-Z:/]*)$ index.php?PageCall=$1 [L,QSA]
页面显示与 $_GET 变量相关的 php 错误。
我做错了什么?
提前致谢。
编辑:我自己回答。似乎 AllowOverride On 也必须写在 httpd.conf 中。所以我找了
# forbid access to the entire filesystem by default
<Directory />
Options None
AllowOverride None
Require all denied
</Directory>
并将 AllowOverride 更改为“全部”。
【问题讨论】:
-
$HOME/public_html/mywebsite是否与/~user/mywebsite相同? -
是的。 mywebsite 的绝对路径是 /home/user/public_html/mywebsite 和其他没有 .htaccess 的网页链接到 localhost/dhouard/someothepage
标签: php apache .htaccess mod-rewrite