0

When rewriting the URLs for my MVC style application with RewriteRule(s) in my .htaccess file I am having a problem with the URL getting longer and longer. There you can find a (not) working example: https://rossi.klingt.org/new/

I've tried several rewriting rules i found here like in this question

I'm running: Linux 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5 (2019-06-19) x86_64
PHP Version 7.2.9-1 Can't get the exact Apache version

The code I'm using in my .htaccess file in the folder /new/ at the moment is this:

<IfModule mod_headers.c>
  Header always append X-Frame-Options SAMEORIGIN
  Header set X-XSS-Protection "1; mode=block"
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /new
  RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR]
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} -d [OR]
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (^.*) index.php [L]
</IfModule>

If you click a link, it will be added to the end of the URL. I expected it to behave differently. I did a similar thing on a pretty old system and it only kept the last folder and did not add them up.

What am I missing? Any help would be appreciated! Thank you all!!

  • Those ``[OR]`` conditionals do not make any sense at all... You basically ask: if the requested _is or is not_ a file... – arkascha Jul 16 '19 at 13:10
  • The [OR]s are a hacky way of telling mod_rewrite to forward to index.php no matter if a file or directory exists or not. This means that directories may exist and will not be browseable. I have a virtual folder structure and a actual folder structure and i don't want my actual folders to interfere with the virtual folders. – nodFlindors Jul 17 '19 at 10:59
  • No, that is not what those lines code, sorry. – arkascha Jul 17 '19 at 17:16
  • Ok, I got that. I am learning here... I followed the answer i found here: https://stackoverflow.com/questions/18406156/redirect-all-to-index-php-using-htaccess#18406686 Can't post my current .htaccess code - I'll add it to my answer! – nodFlindors Jul 18 '19 at 09:25

1 Answers1

0

OK, I just found out what went wrong.

I was looking for a solution in the wrong place. By adding a tag to my section the browser now knows how to deal with the relative paths of my links and does not glue the new link on to the right end of the URL!

My current .htaccess code is the following

Options -MultiViews
Options -Indexes

<IfModule mod_headers.c>
    Header always append X-Frame-Options SAMEORIGIN
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /new
    RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L,NC,QSA]
</IfModule>