hi i have use many different htaccess codes, but i cant get rewrite to work.
i want this url
https://domain.com/category.php?cat=firm
to look like this url
https://domain.com/category/firm
this is my latest attempt
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^/]*).html$ /category.php?cat=$1 [L]
ErrorDocument 404 https://seoboost.no/404page.php
RewriteCond %{HTTP_HOST} ^www.seoboost.no$
RewriteRule ^/?$ "https://seoboost.no/" [R=301]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^/?$ "https://example.com/" [R=301,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F]
RewriteRule ^index.php$ / [R=301]
RewriteRule ^(.*)/index.php$ /$1/ [R=301]
i have try to delete all in my htaccess and only have this code
RewriteEngine on
RewriteRule ^([^/]*).html$ /category.php?cat=$1 [L]
but it still not working, is my server or what am i doing wrong??
2
Answers
Try replacing your .htaccess with
which will redirect
yoursite.com/category/12
toyoursite.com/category.php?cat=12
internally, and the user will never see the “ugly” url. Then inside your category.php file you can access the cat by$category_id = $_GET['cat']
A simple anchor tag looks like this:
Pulling from Justin Lurman’s answer here, the following should work:
As Justin noted in that answer to a similar question, you need to confirm that htaccess files are enabled/allowed in your Apache configuration and that
mod_rewrite
is enabled.Additionally, I am sure you are aware, but just in case you are not, after implementing this new htaccess redirect rule, you should change all of the links on your webpages to use clean/friendly URLs. By doing so, neither your users nor a search engine crawler will access the “ugly” URLs unless they access them directly (via a bookmark or a saved link).