0

Is it possible to have my ".htaccess" file with rewrite rules only apply in a folder it is in? As it is applying it to everything even other directories.

HTAccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]+)/?$ pages.php?page=$1

</IfModule>
  • Could you pls add your .htaccess file. Make sure not to include sensitive information. – Holger Böhnke Dec 18 '21 at 18:23
  • Hey, I just did that. – Leadwizzer492 Dec 18 '21 at 22:19
  • The directives you've posted essentially already do as you require? The regex `^([^/]+)/?$` only matches a single path segment (ie. the current directory) and the preceding _condition_ already excludes directories (for any URL-paths that do end in a slash). (?) – MrWhite Dec 19 '21 at 00:06
  • Please give examples of URLs that, as you suggest, are being rewritten by the above directives but should not be. – MrWhite Dec 19 '21 at 01:09
  • So Issue is, whenever I use this RegEx all my CSS, Images, JS break. They result in a 404 and are also rewritten to the url like pages?php=page=somejshere – Leadwizzer492 Dec 19 '21 at 14:22
  • Are you sure the `REQUEST_FILENAME` contains a proper value at that stage of the apache request processing? Might try `REQUEST_URI` instead. See https://serverfault.com/a/1062617/393657. Also you can pimp the logging so it shows you more details about the rewrite: https://stackoverflow.com/a/9632952/1614903. The latter might not be possible, in a shared hosting with no access to the apache config. – Holger Böhnke Dec 20 '21 at 12:51

0 Answers0