Reputation: 3004
We have an website whose url structure is undergoing major changes. As there are lots of pages, I am trying to find a method that redirects based on the requests file structure AND the lack of a file extension.
The webpages are primarily one of two version:
The end goal is:
I know I can assign a condition to point to a specific redirect for the second example, as in the upper code block. And I can do a simple redirect for the first example. But disappointingly both rewrites effect the urls with multiple/file/folders structure and I end up with two redirects, one with the new folder and one with the original folders.
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{DOCUMENT_ROOT}/multiple/$1 -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^multiple/folder/levels/(.*)$ /learn/$1.htm [R=301,NC,L]
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.htm [R=301,NC,L]
Is there RewriteCond that says CAN NOT contain a specific file structure? Thanks
Upvotes: 0
Views: 56
Reputation: 784958
You may try these rules that won't affect each other:
RewriteEngine On
RewriteRule (?:/|\.[a-z0-9]{3,4})$ - [L,NC]
RewriteRule ^multiple/folder/levels/(.+)$ /learn/$1.htm [R=301,NC,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/learn/ [NC]
RewriteRule ^(.+?)/?$ $1.htm [R=301,NE,L]
RewriteCond %{REQUEST_URI} !^/learn/ [NC]
will prevent second redirect rule to execute after first redirect.
Make sure to clear browser cache or use a new browser for testing this change.
Upvotes: 1