简体   繁体   中英

htaccess redirect infinite redirect

I have an htaccess RewriteRule that displays the url auth/register.php as /register like so:

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. 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? Thanks!

You need to write an Alias.

Here RewriteRule will always redirect you to the new url. So using that is making you to REDIRECT to /auth/register.php . Also you wrote one Redirection rule which is redirecting to /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. 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

Redirect /auth/register.php /register

Don't include

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

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