We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Index.php rewrite on Ubuntu

Development and Programming

ottercreate's avatar
ottercreate
15 posts
4 years ago
ottercreate's avatar ottercreate

Has anyone had issues getting the mod_rewrite to work through .htaccess file when site is hosted on Ubuntu 20.04? I cannot get this to work.

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

Do you have RewriteEngine on set in your virtual host?

       
ottercreate's avatar
ottercreate
15 posts
4 years ago
ottercreate's avatar ottercreate

Hi Andy,

Thank you for your speedy response. Would that be set in the 000-default file? (/etc/apache2/sites-available/000-default.conf)

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

I can’t answer for your specific server, but you should be looking for the .conf file that matches your site’s url and doc root in the ServerName and DocumentRoot directives.

       
ottercreate's avatar
ottercreate
15 posts
4 years ago
ottercreate's avatar ottercreate

I am not sure I understand the specific line we need in that .conf file and where to put it. Currently at the end, we have this:

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

Is there an additional line of code to be added here?

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

Looks like to enable to module you actually just need to run sudo a2enmod rewrite (sorry, it’s been a while since I’ve managed an Apache server). I’d suggest that you review this article and start at “Section 1—How to Activate Mod_Rewrites” https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite#Section%201

       
ottercreate's avatar
ottercreate
15 posts
4 years ago
ottercreate's avatar ottercreate

We had already found that article and ran that code. Got the response that it was already enabled.

       
ottercreate's avatar
ottercreate
15 posts
4 years ago
ottercreate's avatar ottercreate

Is there a different version of code that should go in .htaccess for this environment?

(though even a simple code test for a redirect did not appear to function correctly either)

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

can you post your current htaccess file (or a redacted version)?

       
ottercreate's avatar
ottercreate
15 posts
4 years ago
ottercreate's avatar ottercreate
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/=======/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
   
    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

awesome. I’ve got to head out for the night, but I spin up an apache server tomorrow and test.

       
ottercreate's avatar
ottercreate
15 posts
4 years ago
ottercreate's avatar ottercreate

Our engineer just figured out what was wrong. We had to add that virtual server info (the <Directory…> code) to the SSL config too.

       
Andy McCormick's avatar
Andy McCormick
322 posts
4 years ago
Andy McCormick's avatar Andy McCormick

ah. that makes sense. glad you figured it out.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.