简体   繁体   English

根和索引。php 重定向到新的 url

[英]root and index.php redirect to new url

please what I must change in this htaccess file to get this?:请问我必须在这个htaccess文件中改变什么才能得到这个?:

example.com -> redirect -> example.com/newhp example.com -> 重定向 -> example.com/newhp

example.com/index.php -> redirect -> example.com/newhp example.com/index.php -> 重定向 -> example.com/newhp

I tried this:我试过这个:

.htaccess rewrite to redirect root URL to subdirectory .htaccess 重写以将根 URL 重定向到子目录

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.我猜是因为我需要重写或删除当前 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:在文件顶部附近的RewriteBase指令之后立即尝试以下操作:

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).使用 mod_rewrite 来启动仅对文档根的“直接”请求的重定向(与重写请求相反)。


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.您不会在 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.请注意为什么这会触发 500 内部服务器错误 - 您需要检查服务器错误日志中的详细信息。

This would ordinarily trigger a 302 (temporary) redirect.这通常会触发 302(临时)重定向。 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.但是, RedirectMatch是一个 mod_alias 指令,因此将在所有现有的 mod_rewrite 指令之后进行处理 - 尽管配置文件中的指令顺序不同。 This can result in unexpected conflicts.这可能会导致意外的冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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