Search code examples
.htaccesspermalinks

HTACCESS creating permalinks


I want to rewrite "http://domain.com/url-name/", to look at "http://domain.com/?url="url-name".

I am trying this but with no success :

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]*)\$/  ^([^/]*)?url=$1

Solution

  • There are few mistakes:

    • In regex, if you escape $ then it will match literal $.
    • In the target URI, you cannot use regex but provide back-reference to captured value in the pattern.
    • Use RewriteCond to affect only non-files and non-directories.

    Change your code to this:

    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* ?url=$0 [L,QSA]