Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

calin.ionut's avatar

301 redirects in .htaccess not working

I have deplyoyed my laravel app (5.7) on a VPS server (vultr) and i have some problems with 301 redirects.

The server is using LAMP (ubuntu 18.04)

In the .htaccess I put some 301 redirects (~40 lines - old urls from old app)

Redirect 301 /create-account.html /register

more details here (https://stackoverflow.com/questions/52591029/how-can-i-make-rewrite-module-in-apache-works)

If I remove the redirects the server works perfect, if i add them to the .htaccess file the server crash and in the log (apache log) i see:

/var/www/example.com/html/.htaccess: Invalid command 'Register', perhaps misspelled or defined by a module not included in the server configuration

Any idea why??

0 likes
9 replies
D9705996's avatar

If I remove the redirects the server works perfect,

Do you mean that when remove the redirect directives from the apache configuration your redirection work and just a question about why you are getting errors or do you need help?

I would be tempted to let laravel handle you redirects within your routes rather than within your .htaccess. https://laravel.com/docs/5.7/redirects

calin.ionut's avatar

I mean when removing the lines from htaccess (Redirect 301 old_route new_route) - all of them the app is loading.

The same project on a localhost environment works with the 301 redirects from htaccess.

D9705996's avatar

Do you have mod_rewrite enabled on the other server where it isnt working.

Create file in the public folder phpinfo.php containing

<?php

  phpinfo();

?>

The goto http://yoursite.com/phpinfo.php and see if you see mod_rewrite anywhere? If not install the mod_rewrite package and restart apache and try again.

Apache syntax errors are usually either missing modules or directives in the wrong place.

And make sure you remove the phpinfo script as soon as you confirm mod_rewrite is installed. It a huge security hole to expose publicly

Cronix's avatar

Not having to do with this, but I'd also move the redirects to up above the laravel specific rewrite rules.

Cronix's avatar

@D9705996 I don't think that's the issue, or his laravel app wouldn't work since it's all in an <IfModule mod_rewrite.c> block

D9705996's avatar

@Cronix - just doubling checking the stack overflow .htaccess is from the server isn't from localhost.

same project on a localhost environment works

calin.ionut's avatar

@Cronix same project on a localhost environment works => the same files that are deployed on a public vps server are running too on a private network localhost (not public network)

In htaccess is the problem...and i don`t know which.

Like i said if I ONLY REMOVE the lines that contains the 301 redirects works on vps. The same htaccess run and works perfect on a local environment

The mod rewrite is enabled in apache

D9705996's avatar

Looking at the documentation examples the URLs are qouoted

Redirect "/foo.html" "/bar.html"

However in your examples they are not

Redirect 301 /create-account.html /register

Can you try changing to

Redirect 301 "/create-account.html" "/register"

Please or to participate in this conversation.