1

I want to redirect all requests from root/test.php to root/pages/test
I already managed to eleminate the need for the .php extension by inserting ...

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

... into my htaccess.
But how can I additionally achieve that all pages are actually stored in /pages?
I tried to change RewriteRule ^(.*)$ $1.php to RewriteRule ^(.*)$ /pages/$1.php but that only works if I have a file with the same name in my webroot.

The reason for this is, that I dont want to have all my pages in the webroot folder since there are a lot of pages and I want to keep my root folder 'clean'.

Thx already!

jam0
  • 33
  • 6
  • I tried to add `RewriteRule ^(.*)$ /pages/$1.php [NC,L]`, but that triggers `root/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/pages/test.php` – jam0 Oct 01 '19 at 12:30
  • `RedirectMatch 301 (.*)\.php$ /pages/$1.php` also gives that same huge URL. I think that this is because the index.php itself gets redirected. May this be the issue? If so: How to ignore the /index.php? – jam0 Oct 01 '19 at 12:44
  • https://stackoverflow.com/a/5185461/10955263 – 04FS Oct 01 '19 at 13:53
  • @04FS Tanks! That solves 50% of my problem. But I still can't get the whole Rewrite to work ... :/ – jam0 Oct 01 '19 at 13:56

0 Answers0