1
votes

I have an interesting .htaccess config on my ROOT that looks like this:

    RewriteEngine On
    # add a trailing slash if portal-pages/$1 is a directory
    RewriteCond %{DOCUMENT_ROOT}/portal-pages/$1 -d

    RewriteRule ^(.*[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(?!portal-pages/)(.*)$ portal-pages/$1 [L,NC]

So my real path would be something like this:

 local.com/portal-pages/home

but the .htaccess translates this path to this:

 local.com/home

it works great, but if I hit local.com I want it to forward to local.com/home. if I hit local.com/whatever that just goes to /whatever.

How can I do this with this configuration? Thanks in advance.

also, how can I force everything to https?

1
That first rewrite condition does not make any sense at all. What is $1 meant to be?arkascha
Also the other directives are very strange, like dummies doing nothing at all in a complicated way...arkascha
Can you clarify if I hit local.com I want it to ONLY redirect to local.com/home if I hit local.com/whatever that just goes to /whatever. statement?anubhava
Thanks @anubhava this is kind of confusing I'll edit my phrasing. I just want local.com to forward to local.com/home thats all.John

1 Answers

1
votes

You can use one additional rule to rewrite landing page to /home another redirect rule for http -> https:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

# add a trailing slash if portal-pages/$1 is a directory
RewriteCond %{DOCUMENT_ROOT}/portal-pages/$1 -d
RewriteRule ^(.*[^/])$ %{REQUEST_URI}/ [L,R=301,NE]

# forward landing page to /home
RewriteRule ^/?$ /home [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!portal-pages/)(.*)$ portal-pages/$1 [L,NC]