简体   繁体   English

htaccess重定向无限重定向

[英]htaccess redirect infinite redirect

I have an htaccess RewriteRule that displays the url auth/register.php as /register like so: 我有一个htaccess RewriteRule,将url auth/register.php显示为/register如下所示:

RewriteCond %{REQUEST_URI} register
RewriteRule ^register/?$ /auth/register.php [NC,L]

However, now when someone manually types in auth/register.php into the browser window, I need to make sure they see /register instead. 但是,现在当有人手动在浏览器窗口中输入auth/register.php ,我需要确保他们看到的是/register I was using 我在用

Redirect /auth/register.php /register

But obviously this creates an infinite redirect loop. 但这显然会造成无限重定向循环。 Any ideas on how I can make it so any attempts to go to /auth/register.php go to /register but it still displays the contents of the auth/register.php without redirecting forever? 关于如何实现此目标的任何想法,以便任何尝试进入/auth/register.php尝试都进入/register但仍显示auth/register.php的内容而不会永久重定向? Thanks! 谢谢!

You need to write an Alias. 您需要编写一个别名。

Here RewriteRule will always redirect you to the new url. 在这里,RewriteRule将始终将您重定向到新的URL。 So using that is making you to REDIRECT to /auth/register.php . 因此,使用它可以将您重定向到/auth/register.php Also you wrote one Redirection rule which is redirecting to /register . 您还编写了一个重定向规则,该规则将重定向到/register So this is an infinite loop of these two redirects. 因此,这是这两个重定向的无限循环。

Code that should be written is 应该写的代码是

Alias /register /auth/register.php 

this should not be written in .htaccess file. 不应将其写入.htaccess文件中。 It should be written in Virtual host file of your website 它应该写在您网站的虚拟主机文件中

It looks similar to this 看起来与此相似

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /register /auth/register.php //Add this line only donot disturb any other lines


</VirtualHost>

In your .htaccess file only include this line 在您的.htaccess文件中, 仅包括此行

Redirect /auth/register.php /register

Don't include 不包括

RewriteCond %{REQUEST_URI} register
RewriteRule ^register/?$ /auth/register.php [NC,L]

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

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