Reputation: 611
I have spent 2 days on the following problem:
I have a virtual host on an apache 2.4.7 server with the following configuration:
<VirtualHost *:80>
DocumentRoot /home/xxx/test/www
ServerAdmin [email protected]
ServerName test.xxx.com
ServerAlias www.test.xxx.com
AddHandler x-httpd-php5 .php
ErrorLog ${APACHE_LOG_DIR}/xxx-test-error.log
LogLevel warn
LogLevel alert rewrite:trace6
CustomLog ${APACHE_LOG_DIR}/xxx-test-access.log combined
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/xxx/test/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
And an .htaccess file like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^article/([^/\.]+)/?$ article-page.php?name=$1 [L]
RewriteRule ^list/.?$ list.php [L]
RewriteRule ^sitemap.xml$ sitemap.php [L]
</IfModule>
I want to have all the URL started by /list/ treated with list.php
But when I lauch the URL: http://test.xxx.com/list/yyy-category
It just returns a 404. I have checked, the list.php exists and have the good rights.
I checked the logs and I got:
[Sun Feb 14 21:00:23.764091 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] add path info postfix: /home/xxx/test/www/list.php -> /home/xxx/test/www/list.php/yyy-category, referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764163 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] strip per-dir prefix: /home/xxx/test/www/list.php/yyy-category -> list.php/yyy-category, referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764194 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] applying pattern '^article/([^/\\.]+)/?$' to uri 'list.php/yyy-category', referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764228 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] add path info postfix: /home/xxx/test/www/list.php -> /home/xxx/test/www/list.php/yyy-category, referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764259 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] strip per-dir prefix: /home/xxx/test/www/list.php/yyy-category -> list.php/yyy-category, referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764287 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] applying pattern '^list/(.?)$' to uri 'list.php/yyy-category', referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764355 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxxcom/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] add path info postfix: /home/xxx/test/www/list.php -> /home/xxx/test/www/list.php/yyy-category, referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764386 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] strip per-dir prefix: /home/xxx/test/www/list.php/yyy-category -> list.php/yyy-category, referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764414 2016] [rewrite:trace3] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] applying pattern '^sitemap.xml$' to uri 'list.php/yyy-category', referer: http://test.xxx.com/
[Sun Feb 14 21:00:23.764445 2016] [rewrite:trace1] [pid 17393] mod_rewrite.c(468): [client 79.81.246.191:53329] 79.81.246.191 - - [test.xxx.com/sid#66dd81c14970][rid#66dd81b400a0/subreq] [perdir /home/xxx/test/www/] pass through /home/yyy/test/www/list.php, referer: http://test.xxx.com/
Any idea on how to fix this ?
Upvotes: 0
Views: 2331
Reputation: 611
I have found it, it's something really stupid in fact. As seen in the logs, it tries to make it match with the following file and it's not a good path
home/xxx/test/www/list.php/yyy-category
The best way not to confuse apache is not have the file with a name completeny different from the URL prefix like "list-page.php". The rule that works is now:
RewriteRule ^list/(.+)?$ list-page.php?query=$1 [L]
Upvotes: 0
Reputation: 361
Your .htaccess matches urls which start with "list/" and are followed by one character, or none (that's what .? means).
In your case, you have to change the rule that way:
RewriteRule ^list/.*$ list.php [L]
The .* symbols mean "I want any character, 0 or more times".
Upvotes: 1