0

I want to redirect all requests for subpages to the directory root. Unfortunately I only get redirect loops. Here is a sample of my .htaccess-file:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^parent-directory/.*$ /parent-directory [L,R=301]

Although I understand why there is a redirection loop I can’t think of a working solution despite searching for hours.

schuggerleo
  • 45
  • 1
  • 2
  • 8

1 Answers1

0

.* means 0 o more characters of any type

Use .+ to make it 1 or more and discard /parent-directory redirecting onto itself

Daniel Ferradal
  • 2,415
  • 1
  • 8
  • 13
  • Thank you for your answer ezra-s! Although it did not work out the way you described it, the hint with wildcard-characters helped! My mod_rewirte-Module now looks similar to this and it works: `RewriteEngine OnRewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^parent-directory/.+$ /parent-directory [L,R=301]` Most important: No more redirect loops! Thx! – schuggerleo Aug 29 '16 at 15:54
  • Just an additional sidenote, using $ after a .+ or .* is futile. Glad you solved it! :) – Daniel Ferradal Aug 29 '16 at 18:00
  • In fact, instead of `.+$` you can simply use `.` (a single dot). And something like `.*$` can be omitted altogether. (One would assume that the "directory root" is `/`, not `/parent-directory`?) – MrWhite Aug 31 '16 at 00:04