简体   繁体   English

Apache返回403状态代码以及页面内容

[英]Apache returning 403 status code along with page content

I have a cPanel hosting account with my primary domain pointing to public_html . 我有一个cPanel托管帐户,我的主域指向public_html But, to make directory structure better, I add the following code to public_html/.htaccess 但是,为了使目录结构更好,我将以下代码添加到public_html/.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/www\.MyDomain\.com [NC]
RewriteRule ^(.*)$ /MyDomain.www/$1 [NC,L]

It simply redirect all request from /public_html to /public_html/MyDomain.www for my primary domain. 它只是将所有请求从/public_html重定向到我的主域的/public_html/MyDomain.www

But, the problem is when I visit http://www.MyDomain.com/ it dispays page at public_html/MyDomain.www/index.php but with 403 HTTP code instead of 200 which is expected. 但是,问题是,当我访问http://www.MyDomain.com/它将在public_html/MyDomain.www/index.php分配页面,但使用的是403 HTTP代码而不是预期的200。 Note, visiting http://www.MyDomain.com/index.php returns page correctly with 200 HTTP code. 请注意,访问http://www.MyDomain.com/index.php正确返回包含200个HTTP代码的页面。

So, How can I fix the 403 error code? 那么,如何修复403错误代码?

I tried replacing the existing rewrite rule in .htaccess with this and surprisingly it worked. 我试图以此替换现有的.htaccess中的重写规则,但令人惊讶的是它起作用了。

RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !domain.www/
RewriteRule (.*) /domain.www/$1 [L] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM