Pergunta

I am having problems getting what I think should be a simple htaccess rewrite to work...

Current URL: http://www.website.com/profile.php?id=61338848

Desired URL: http://www.website.com/61338848

Current htaccess code:

RewriteEngine On
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]

Result from the above htaccess is INTERNAL SERVER ERROR:

I would also like it to work for a custom domain (if set) although I am sure the solution priovided for the above will work just as well.

Desired URL: http://www.website.com/customdomain

Thanks in advance.

Foi útil?

Solução

i used this .htaccess and it works for me:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ profile.php?id=$1 [L,QSA]

The QSA flag is used, that you can add multiple get parameters like this: http://www.website.com/61338848?parameter=value

RewriteCond %{REQUEST_FILENAME} !-f checks if the request_filename is a file, if yes, the RewriteRule will not be executed

Outras dicas

Try to remove the / before the filename, like:

RewriteRule ^([^/]*)$ profile.php?id=$1 [L]

It worked for me.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top