1

please what I must change in this htaccess file to get this?:

example.com -> redirect -> example.com/newhp

example.com/index.php -> redirect -> example.com/newhp

I tried this:

.htaccess rewrite to redirect root URL to subdirectory

RewriteEngine On

RewriteRule ^$ /newhp [L]

and this:

RedirectMatch ^/$ /newhp

but it didn't work right. I guess because I need rewrite or delete something in my current htaccess.

Sorry for dump question, I am noob in this.

thanks

999999999
  • 13
  • 3
  • "but it didn't work _right_" - So, what happened exactly? Did you get an error? Nothing happened? Incorrect rewrite/redirect? The first rule (`RewriteRule`) you posted is an internal rewrite, the second (`RedirectMatch`) is a temporary redirect. What is `/newhp`? How is this handled by your server? – MrWhite Mar 26 '21 at 00:54
  • RewriteRule didn't do anything - no redirect. RedirectMatch gives me this error: **Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log.** – 999999999 Mar 26 '21 at 02:35
  • I guess I need remove some other part of that code https://i.stack.imgur.com/tCjjZ.png, where are some redirects or rules to index – 999999999 Mar 26 '21 at 02:38
  • /newhp has same content as root/index.php, but I need to redirect it to /newhp – 999999999 Mar 26 '21 at 02:42
  • 1
    Please include the content of your existing .htaccess in the question, in text form & properly formatted, instead of showing _a screenshot_ of it. And explain/show, _where_ in that context you added the new stuff. – CBroe Mar 26 '21 at 07:22

1 Answers1

0

Try the following instead, immediately after the RewriteBase directive near the top of the file:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^$ /newhp [R=302,L]

The uses mod_rewrite to initiate the redirect on "direct" requests to the document root only (as opposed to rewritten requests).


Notes about your attempts:

RewriteRule ^$ /newhp [L] 

This is an internal rewrite, not a redirect. You will not see a visible change in the URL. This is unlikely to work with your front-controller.

RedirectMatch ^/$ /newhp

Note sure why this would trigger a 500 Internal Server Error - you would need to check the details in your server's error log.

This would ordinarily trigger a 302 (temporary) redirect. However, RedirectMatch is a mod_alias directive so will be processed after all your existing mod_rewrite directives - despite the order of directives in your config file. This can result in unexpected conflicts.

MrWhite
  • 23,175
  • 4
  • 44
  • 71
  • 1
    `RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^$ /newhp [R=302,L]` working great! thank you very much a thanks for explanation – 999999999 Mar 26 '21 at 12:53