Search code examples
.htaccesshttp-redirect

Redirect one URL to another using htaccess


My current .htaccess file code is as follows:

### ISPConfig folder protection begin ###
AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/web113/web/.htpasswd
require valid-user
### ISPConfig folder protection end ###


<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L]

</IfModule>

I want to redirect URL as http://xxxxx.xxxxxx.net/local-attraction to http://xxxxx.xxxxx.net/pages/local-attraction

I have tried with

RedirectPermanent http://xxxxx.xxxxxx.net/local-attraction http://xxxxx.xxxxx.net/pages/local-attraction

Also with the

Redirect 301 /local-attraction http://xxxxx.xxxxx.net/pages/local-attraction

But nothing works, it is showing 404 page.


Solution

  • You should use mod_rewrite rule for this redirect since you are already using it your .htaccess:

    RewriteEngine On
    
    RewriteRule ^local-attraction/?$ /pages/$0 [L,NC,R=301]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]