Home > Back-end >  htaccess redirect to exclude certain pages
htaccess redirect to exclude certain pages

Time:11-10

My htaccess file currently redirects everything and has this

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://www.domain.co.uk/$1 [R,L]

I need to exclude two urls that begin with "send"

I changed the last line to

RewriteRule !^send(.*)  https://www.domain.co.uk/$1 [R,L]

It excluded the send urls but any url in a subfolder is redirected to the root index page.

CodePudding user response:

RewriteRule !^send(.*)  https://www.domain.co.uk/$1 [R,L]

Negated patterns don't capture anything (by definition), but trying to capture everything after send when send is not present in the URL, doesn't make much sense.

You can do something like the following and use the REQUEST_URI server variable in the substitution instead of the backreference:

RewriteRule !^send https://www.domain.co.uk%{REQUEST_URI} [R,L]

Note that the REQUEST_URI server variable already contains the slash prefix.

  • Related