1

I'm experiencing a redirection issue in my React JS app where main pages are being redirected to their respective directory paths with a trailing slash (/), resulting in 301 redirect issues.

What I tried:

Configured .htaccess file to prevent trailing slash redirects:

RewriteEngine On
DirectorySlash Off
...

Expected: No redirection to directory paths with trailing slashes. But I am getting one.

  • https://example.com/about/
  • https://example.com/about

1 Answer 1

0
RewriteEngine On
DirectorySlash Off

DirectorySlash Off (mod_dir) is all that you require here. RewriteEngine (mod_rewrite) is unrelated.

However, the 301 (permanent) redirect that resulted before you implemented the DirectorySlash directive is most certainly cached by the browser and possibly intermediary caches. 301s are cached persistently by the browser. These caches will need to be cleared before this directive will have an effect.

Note that if you disable the directory slash then you must also ensure that auto-generated directory listings (mod_autoindex) are also disabled since a DirectoryIndex document in a directory will no longer prevent the directory listing being generated when a slash is omitted from the URL-path.

# Disable directory listings (mod_autoindex)
Options -Indexes

However, instead of disabling the directory slash on the server it would be preferable to avoid this conflict to begin with, to avoid URL-paths also mapping to physical filesystem directories.

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.