Search code examples
apache.htaccessurlmod-rewriteurl-rewriting

Pretty URLs with .htaccess rewrite engine


Hej,

I'm trying to achieve a pretty urls for my site with rewrite engine. The goal is this - mysite.dk/da, mysite.dk/da/success and mysite.dk/da#scroll.

So far my htaccess file looks like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
DirectoryIndex /index.php

I tried to implement this

RewriteRule ^da$ da.php [L]
RewriteRule ^da/success$ success.php [L]

but that didn't really help:/ Thanks


Solution

  • Have it like this:

    # Default index
    DirectoryIndex index.php
    
    # disable directory listing and MultiViews
    Options +FollowSymLinks -MultiViews -Indexes
    
    # disable automatic addition of trailing / after a directory
    DirectorySlash Off
    
    RewriteEngine on
    
    # add .php extension 
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [L]