1
votes

I'am working at the moment on a little PHP project.

For this, is created a simple router class which takes the value of a GET-parameter, splits it up and calls the requested class and method.

My .htaccess file should rewrite the requested url so I can call

http://localhost/class/function

which should be redirected to

http://localhost/index.php?route=class/function

So far so good. Thats working with the following .htaccess-file:

DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [QSA]

But now, if I'am trying to access the base-URL

http://localhost

I'm getting redirected to

http://localhost/var/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.php

which I can't explain myself.

To be honest, I didn't worked a lot of with mod_rewrite until now but this behavior looks way to strange for me.

Hope anyone can help me.

Thanks guys.

Edit 2017-01-15

It looks like that it has nothing to do with the htaccess file.

At first I tested my file with this validator and it seems like it works like I wanted.

I tried to delete the htaccess file and I have still the same problem. So I assume that it is caused by the apache2 webserver.

I set the LogLevel in my virtual host to debug and got the following information from it:

[Sun Jan 15 09:33:41.684274 2017] [authz_core:debug] [pid 2183] mod_authz_core.c(809): [client 10.0.2.2:49743] AH01626: authorization result of Require all granted: granted

[Sun Jan 15 09:33:41.684355 2017] [authz_core:debug] [pid 2183] mod_authz_core.c(809): [client 10.0.2.2:49743] AH01626: authorization result of : granted

[Sun Jan 15 09:33:41.684445 2017] [core:info] [pid 2183] [client 10.0.2.2:49743] AH00128: File does not exist: /var/www/public/var/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.phpvar/www/public/index.php

It makes like no sense to my. My config-file for the virtual host contains no rewrite rules.

1

1 Answers

0
votes

The problem caused because it loops everytime you visit the localhost. Try to stop this loop by adding the [L] Flag like the following code: RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]

UPDATE I have created an example which works on my side:

I have created a main index page with takes a page parameter. So, a link like index.php?class=software would take you to a software page, while a link to index.php?class=test would take you to a testpage. With mod_rewrite is to silently redirect users from class/software/ to index.php?class=software etc.

The following is what needs to go into your .htaccess file to accomplish that:

RewriteEngine on RewriteRule ^class/([^/\.]+)/?$ index.php?class=$1 [L]

Also it doesn't loop while visiting the index.php page.