Ad

.htacces How To Write Htacces Rewrite Rule For Seo Friendly Url

- 1 answer

I'm just new to .htacces

I want:

example.com/page.php?page=how-to-learn

changed to: example.com/how-to-learn

I google'd some and tried but no change url.

Ad

Answer

That's not how .htaccess work : it won't change your links to display the corrected version, but it looks for a match in the expressions you'll write into it to rewrite the correct parameters.

For example, in your code, your .htaccess sould look something like this :

RewriteEngine On
RewriteRule ^([a-z-]+)$  page.php?page=$1 [QSA,L]

If you write example.com/how-to-learn in your browser, you'll be able to see the content of example.com/page.php?page=how-to-learn.

I advise you to be VERY careful though : as the expression is VERY permissive, you'll have to check in the page.php file that the file if legitimately allowed to be loaded.

Ad
source: stackoverflow.com
Ad