Thursday, February 8, 2024

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

Issue

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

Solution

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


Answered By - Clay
Answer Checked By - Gilberto Lyons (WPSolving Admin)