简体   繁体   English

将.htaccess传输到生产服务器会出现URL找不到错误

[英]Transferring .htaccess to production server gives URL not found error

I've just spent the afternoon writing an .htaccess file for a project I am working on. 我刚刚花了一个下午为正在处理的项目编写.htaccess文件。

It works in my test environment but when I transfer it to the live server, I get 404 errors: 它可以在我的测试环境中工作,但是当我将其传输到实时服务器时,出现404错误:

The requested URL /albums/hua-hin/ was not found on this server. 在此服务器上找不到请求的URL / albums / hua-hin /。

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle >the request. 此外,尝试使用ErrorDocument处理请求时,遇到404 Not Found错误。

My .htaccess is as follows: 我的.htaccess如下:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^albums/([^/]+)/image/([^/]+)/([^/]+) /getimage.php?a=$1&i=$2&pt=$3 [NC]
RewriteRule ^albums/([^/]+)/tags/([^/]+) /index.php?a=$1&tag=$2 [NC]
RewriteRule ^albums/([^/]+)/sag/([^/]+) /index.php?a=$1&sag=$2 [NC]
RewriteRule ^albums/([^/]+)/ /index.php?a=$1 [NC]

I wonder if the way my server is set up has anything to do with it. 我想知道我的服务器设置方式是否与此有关。 It's a shared account on which I host multiple sites. 这是一个共享帐户,我可以在该帐户上托管多个网站。

www.mymaindomain.com points to the root of (my space on) the server. www.mymaindomain.com指向服务器(我在其上的空间)的根目录。 There is an .htaccess file there which then points all traffic from www.mymaindomain.com to (root)/mymaindomain 那里有一个.htaccess文件,该文件随后将所有来自www.mymaindomain.com的流量都指向(root)/ mymaindomain

this site is located in (root)/anotherdomain, and is directly pointed there. 该站点位于(根)/另一个域中,并直接指向该站点。

I have other sites at (root)/domain3, (root)/yetanotherdomain etc; 我在(root)/ domain3,(root)/ yetanotherdomain等处还有其他站点; none of which use .htaccess files as far as I remember! 据我所记得,没有一个使用.htaccess文件!

OK I have found the issue! 好的,我已经找到了问题!

I have a file in the root called albums.php, and all my redirects are basled on /albums/ 我在根目录中有一个名为albums.php的文件,所有重定向均位于/ albums /

For some reason, while this didn't cause any issues in the testing environment, it caused the production server to 404 on me. 出于某种原因,尽管这在测试环境中没有引起任何问题,但是却导致生产服务器出现404错误。 Renaming the albums.php file to something different solved the problem. 将albums.php文件重命名为其他名称可以解决该问题。

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

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