How to enable Url Rewriting (mod_rewrite)

How do I enable Url Rewriting (mod_rewrite) in my HestiaCP. Thanks in advance

It is enabled in mine but I may have done it manually

ls -1 /etc/apache2/mods-enabled/ | grep rewrite
rewrite.load

to activate module rewrite in debian based OS use the a2enmod command

sudo a2enmod rewrite 
then
sudo systemctl restart apache2

read about it here

running this : “sudo a2enmod rewrite” shows already enabled.

this also shows shared:
image

What am i missing?

Did you add the .htaccess file to your document root with the rewrite rules required by your web app?

Not sure but this what i have in .htaccess file.

RewriteEngine on
RewriteRule ^sitemap/list_([0-9]+).xml$ user-uploads/sitemap/list_$1.xml [L]
RewriteRule ^sitemap.xml$ user-uploads/sitemap.xml [L]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/svg+xml "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymlinks
Options -Multiviews
RewriteEngine on
RewriteBase /
RewriteRule ^cache/(.*)/images/(.*) /images/$2 [L]
RewriteRule ^cache/(.*)/fonts/(.*) /fonts/$2 [L]
RewriteRule ^(scripts|user-uploads/text-editor|user-uploads/sitemap.xml|user-uploads/sitemap|.well-known) - [L]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

I don’t know whether you need above section.

Show the output of these commands (replace YourUser and YourDomain with the actual data).

cat /home/YourUser/conf/web/YourDomain/apache2.conf
cat /home/YourUser/conf/web/YourDomain/apache2.ssl.conf

All looks good, also, I checked your site and seems rewrite is working.

server_info.php - Google Drive it shows off

You should ask to FatBit how they check that url rewriting is enabled because it is in your web site.

@Thanks. But do i have to include this in the apache2 conf file or all is ok?

<Directory /var/www/>
AllowOverride All
Options FollowSymLinks
Require all granted

You don’t need to add that conf, the conf you have is ok.

This is what was use it to check the options

My php knowdledge is zero, so I can’t help to review that file.

@sahsanu You have done enough sir :innocent: Im grateful

Thank you.

I tested the script in one of my test sites where url rewritting is enabled and I also get this:

So, you shouldn’t be worried, url rewritting works.

1 Like

@sahsanu :pray:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.