Search code examples
regex.htaccessdirectoryurl-rewriting

How to make url like directory style using .htaccess


I'm currently using htaccess in my personal project but i could not make urls works like sitename.com/a/b/c

My base urls: sitename.com/index.php?category=category-name&page=3 How to make this url like sitename.com/category-name/3 or sitename.com/category-name/3/page-name (or page-name.html)

my .htaccess file:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z]+)/([0-9]+)/?$ index.php?category=$1&page=$2 [L]

It does not work and css, js file does not work. How to make this works? Can anyone help me?


Solution

  • Try this:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(\w+)/([0-9]+)/?$ index.php?category=$1&page=$2 [L]
    RewriteRule ^(\w+)/([0-9]+)/(\w+)/?$ index.php?category=$1&page=$2&page-title=$3 [L]