I've created a .htaccess file for my site running on my own server, Apache Ubuntu 22.04, where everything works fine except for Rewrite Rule. I definitely have mod_rewrite turned on as when I created a php file with phpinfo(); it appears in the loaded modules. I have also gone into the apache.conf and sites-enabled conf files and turned AllowOverride to All.
the Redirect Rule works completely fine with no issue yet whenever I try to use the Rewrite Rule it never seems to work.
This code works:
Redirect /foobar/ https://example.com
However this code doesn't:
RewriteEngine on
RewriteRule ^foobar/$ https://example.com/ [R]
This is what I have changed in my apache2.conf file
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
Would anyone know why this could be, as nothing I've tried works and any help would be greatly appreciated.
.htaccess
file? Do you have any other directives in the.htaccess
file? (Do you have any other.htaccess
files in subdirectories?) By "doesn't work" you mean it's literally not doing anything? No error? Presumably typing some "nonsense" in the.htaccess
breaks with a 500 error? What is theDocumentRoot
? I would not expect this to be/var/www/
(on later versions), more likely to be/var/www/html
(however, it would be preferable to customise this further in a vHost). If the.htaccess
file is not in the docroot then theRewriteRule
will not match.