1

I have a .htaccess code which is given below.

RewriteCond %{HTTP_HOST} ^app.vdsta\.com$ [NC]
  RewriteCond %{REQUEST_URI} /admin-panel
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule ^admin-panel(?:/(.*))?$ /staging/admin-panel/$1 [L]

  RewriteCond %{HTTP_HOST} ^app.vdsta\.com$ [NC]
  RewriteRule ^((?!((vdsta_app/website)|(staging/admin-panel))/).*)$ /vdsta_app/website/$1 [L,NC]

The issue is when I type the URL https://app.vdsta.com/admin-panel it leads me to a blank page. But when I just add a slash like this: https://app.vdsta.com/admin-panel/, it works fine.

So how can I set in .htaccess so that when I type https://app.vdsta.com/admin-panel it will redirect to https://app.vdsta.com/admin-panel/?

3
  • 3
    So how can i set in htaccess so that when i type "https://app.vdsta.com/admin-panel" and it will redirect to "https://app.vdsta.com/admin-panel" your both shown urls are looking fine, could you please correct them in your question once? Commented Nov 26, 2020 at 10:42
  • So how can i set in htaccess so that when i type "app.vdsta.com/admin-panel" and it will redirect to "app.vdsta.com/admin-panel" It is actually like this. please review. Commented Nov 27, 2020 at 10:10
  • Could you please change your admin-panel rule to something like RewriteRule ^admin-panel/(.*)?/?$ /staging/admin-panel/$1 [L] once and try, make sure you clear your browser's cache and try it. Let me know how it goes then. Commented Nov 30, 2020 at 10:33

1 Answer 1

1

So how can I set in .htaccess so that when I type https://app.vdsta.com/admin-panel and it will redirect to https://app.vdsta.com/admin-panel/?

You can add the following redirect directive before your existing rules:

RewriteCond %{HTTP_HOST} ^app.vdsta\.com$ [NC]
RewriteRule ^admin-panel$ /$0/ [R=301,L]

Make sure you are linking to the URL with the trailing slash throughout your site, otherwise you will get a log of unnecessary redirects.

Test first with a 302 (temporary) redirect and only change to a 301 (permanent) - if that is the intention - once you have confirmed this works OK.

The $0 backreference contains the matched URL-path (ie. admin-panel), to which we append a slash for the redirection.

HOWEVER, I would be curious to know why this is resulting a "blank page" to begin with? Are you using relative client-side URL-paths (to CSS, JS, images, ...)? The fact that you have tagged the question javascript perhaps suggest this is JS related. Otherwise the first internal rewrite directive behaves exactly the same whether a trailing slash was present on the initial request or not - the trailing slash is essentially appended during the internal rewrite. So, something else (I guess client-side JS) is resulting in the "blank page".

Aside:

RewriteCond %{REQUEST_URI} /admin-panel

This first RewriteCond directive is entirely superfluous.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.