• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: htaccess redirect to certain subdirectory if none given

Resolved: htaccess redirect to certain subdirectory if none given

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve htaccess redirect to certain subdirectory if none given

Question:

I am trying to redirect base URL to certain subdirectory, only if the base URL is requested. E.g. Redirect www.example.com to www.example.com/en. But if the URL already contains a subdirectory (eg. www.example.com/de), no redirection should take place.
How can this be done via .htaccess?

Best Answer:

Using mod_rewrite at the top of the root .htaccess file to redirect the root-directory-only to /en:
But note that if /en is a physical directory on the filesystem then you should be redirecting to /en/ (with a trailing slash), not /en. Otherwise, mod_dir will trigger a second redirect to append the trailing slash.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

.htaccess mod-rewrite redirect
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: net::ERR_HTTP2_PROTOCOL_ERROR by http get request angular 15.2

02/04/2023

Resolved: How do I stop the command from happening if the requirements for it to work aren’t sert Discord.js

02/04/2023

Resolved: How to scroll bottom of div at launch?

02/04/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.