Search code examples
.htaccessurlmod-rewritehyperlinksef

SEF Links with mod_rewrite error 500


Hey i want to rewrite my links

mydomain.com/?page=pageName

to

mydomain.com/pageName

I tried with

RewriteEngine On
RewriteRule ^([^/]*)$ /?page=$1 [L]

but it seems to to give an error 500


Solution

  • You have an infinite loop because of your rule.
    You must add a condition to avoid it

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/(index\.php)?$
    RewriteRule ^([^/]*)$ /?page=$1 [L]
    

    EDIT: taking your comments into consideration

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_URI} ^/(index\.php)?$
    RewriteRule ^ - [L]
    
    RewriteRule ^([^/]*)/([^/]*)$ /?page=$1&id=$2 [L]
    RewriteRule ^([^/]*)$ /?page=$1 [L]