public_html中的.htaccess返回404页面

时间:2015-01-19 09:08:42

标签: php apache .htaccess mod-rewrite

我是.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更改为&#34;全部&#34;。

1 个答案:

答案 0 :(得分:0)

当你在子目录中工作时,你必须提到RewriteBase为

RewriteBase /home/yourusername/public_html/mywebsite

在RewriteEngine的下一行添加此行。