简体   繁体   English

该URL如何在Apache中映射?

[英]How is this URL being mapped in Apache?

I've taken over a project where the old developer just disappeared, and my first self-assigned task is to be able to replicate the entire stack on an EC2 host. 我已经接管了一个旧开发人员刚刚消失的项目,而我的第一个自我分配任务是能够在EC2主机上复制整个堆栈。

On the original pre-existing host, I can hit a URL that is http://www.example.com/users/login/ (I can drop the trailing slash and it hits the login page just fine). 在原来的原始主机上,我可以访问一个URL,即http://www.example.com/users/login/ (我可以加上斜杠,并且可以正常登录到登录页面)。

Looking through the source code in /var/www/[example.com]/ -- I can find a sections/users/login.php that looks like it is where the HTML page is rendered from. 查看/var/www/[example.com]/中的源代码-我可以找到一个看起来像是从中渲染HTML页面的section / users / login.php。

I have this same code in my secondary EC2 host, however I'm not bothering to use virtual hosts, I'm just putting it in /var/www/html/ (rather than /var/www/[example.com]/), but I'm getting a 404. 我的辅助EC2主机中有相同的代码,但是我不费心使用虚拟主机,我只是将其放在/ var / www / html /中(而不是/var/www/[example.com]/ ),但我得到了404。

Where should I look for the mapping that points the http://www.example.com/users/login/ to /sections/users/login.php? 我应该在哪里寻找将http://www.example.com/users/login/指向/sections/users/login.php的映射?

I am not that well-acquainted with RewriteRule stuff, but the only 2 .htaccess files in the repo, and in the httpd.conf, I see nothing to do with 'sections' anywhere, so I'm not sure where to look. 我对RewriteRule的东西不是很熟悉,但是在仓库和httpd.conf中只有2个.htaccess文件,我在任何地方都看不到与“ sections”有关的内容,所以我不确定在哪里查找。

The .htaccess in my root directory is: 我的根目录中的.htaccess是:

php_value post_max_size 1024M
php_value upload_max_filesize 1024M
php_value memory_limit 1024M
php_value max_input_time 1800
php_value max_execution_time 1900
php_value session.gc_maxlifetime 7200

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^(.*)example.mobi [NC]
    RewriteRule ^(.*)$ http://%1example.com/$1 [R=301,L]

    RewriteCond %{HTTP_HOST} ^(.*)example.us [NC]
    RewriteRule ^(.*)$ http://%1example.com/$1 [R=301,L]

    RewriteBase /

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

    RewriteRule ^(.*)\.vcf vcf.php [L]

    RewriteRule ^shared/(.*)$ /$1 [L,NC,R]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

Options -Indexes

First of all, you could paste the content of the htaccess file so we can see the rules you already have. 首先,您可以粘贴htaccess文件的内容,以便我们可以看到您已有的规则。 I believe you should have something like 我相信你应该有这样的东西

RewriteRule ^([^\.]+)$ $1.php [NC,L]

Also, some hosting providers (including AWS EC2 from what I know) will require MultiViews enabled in the apache config. 此外,某些托管服务提供商(包括我所知的AWS EC2)将要求在apache配置中启用MultiViews。

You could also check that your .htaccess file is parsed and used (you can enable rewrite debug level or just add some dummy code in the .htaccess file and wait for an error :)). 您还可以检查.htaccess文件是否已解析和使用(可以启用重写调试级别,也可以仅在.htaccess文件中添加一些伪代码,然后等待错误:)。 If apache doesn't load your .htaccess files, check the AllowOverride and Require settings (you should have AllowOverride All and Require All Granted). 如果apache未加载您的.htaccess文件,请检查AllowOverride和Require设置(您应该具有AllowOverride All和Require All Granted)。

  • Keep in mind that configuration changes will require you to reload the config or restart the apache service. 请记住,配置更改将要求您重新加载配置或重新启动apache服务。

In this case, it appears that the RewriteRule is rewriting all the requests to the index.php file. 在这种情况下,似乎RewriteRule正在将所有请求重写到index.php文件。 This is very common in frameworks but you can accomplish it without a framework. 这在框架中很常见,但是您无需框架即可完成。 Inside the index.php file it is parsing the query string and re-mapping it to the appropriate PHP files. 在index.php文件中,它正在解析查询字符串并将其重新映射到适当的PHP文件。

It should be noted that it will only rewrite to the index.php file if it does not find a matching file or directory in the request - that's what this rule does: 应该注意的是,只有在请求中找不到匹配的文件或目录时,它才会重写为index.php文件-这是此规则的作用:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

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