简体   繁体   中英

Proper mod_rewrite for SEO friendly URLs

I have a custom php script, each having a page for page.php?id=[number] and page.php. I've read a few .htaccess tutorials but I don't know which one is the most appropriate way of doing it: Example,

page.php?id=12 to page/id-12/
and
page.php to page/ AND page

Here's what I currently have:

RewriteEngine On
RewriteRule ^category/([0-9])$ /category.php?id=$1
RewriteRule ^category/$ /category.php

Code above returns 404 not found if i access category but appears okay if i access category/ (with a slash)

All your rules include the slash / at the end of category , thus of course category cannot match it.

RewriteRule ^category/?$ /category.php

The ? after / makes it optional

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM