skip to Main Content

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

2

Answers


  1. To achieve the pretty URLs you want, modify your .htaccess file like this:

    RewriteEngine on
    
    # Specific rewrites
    RewriteRule ^da$ da.php [L]
    RewriteRule ^da/success$ success.php [L]
    
    # General rewrites
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    
    # Default index
    DirectoryIndex index.php
    
    1. Place specific rules for da and da/success at the top so they take precedence.
    2. Use [L] to stop further rewriting for these specific cases.
    3. General rules follow after the specific ones.
    Login or Signup to reply.
  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search