Report this

What is the reason for this report?

Can't get mod_rewrite to work on my Ubuntu 14.04 server

Posted on December 26, 2014

Hi. Can anyone please tell me why my htaccess rewrite is not working? I want to remove the .php extensions and I have the following in my .htaccess file, but to no avail. I am running a LAMP stack on Ubuntu 14.04 x64.

Options -indexes

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /blog

# Allow any files or directories that exist to be displayed directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

<IfModule !mod_rewrite.c> 
ErrorDocument 404 index.php 
</IfModule>

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteRule	about about.php 
</IfModule>

# Apache Rewrite Rules 
<IfModule mod_rewrite.c> 
Options +FollowSymLinks 
RewriteEngine On 
RewriteBase /

# Add trailing slash to url 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$ 
RewriteRule ^(.*)$ $1/ [R=301,L]

# Remove .php-extension from url 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^\.]+)/$ $1.php

# End of Apache Rewrite Rules 
</IfModule>

Can anyone please take a look and tell me what’s wrong with it? Will be much appreciated.

-Sadman.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted

it looks like your link to your stylesheet is the issue. Try changing it to:

/assets/css/style.css

instead of

assets/css/style.css

For anyone else looking for an answer here because their rules for permalinks don’t work, remember to disable Multiviews on top of your htaccess file:

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.