简体   繁体   中英

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.

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).

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.

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.

Where should I look for the mapping that points the http://www.example.com/users/login/ to /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.

The .htaccess in my root directory is:

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. 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.

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 :)). If apache doesn't load your .htaccess files, check the AllowOverride and Require settings (you should have AllowOverride All and Require All Granted).

  • Keep in mind that configuration changes will require you to reload the config or restart the apache service.

In this case, it appears that the RewriteRule is rewriting all the requests to the index.php file. 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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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