简体   繁体   中英

root and index.php redirect to new url

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM