简体   繁体   中英

SEO Friendly URL Command in .htaccess

I have a dynamic page that looks like the following:

www.sitedomain.com/page.php?id=30&name=about_our_company

I want to make my website links SEO friendly by having something like the following:

www.sitedomain.com/about_our_company.html

Or

www.sitedomain.com/about_our_company

My question is: what regex/code I should have in the .htaccess file?

Thanks

You could improve this to be more generic:

RewriteRule ^([^/]+)/([^/]+)?$  /page.php?id=$1&name=$2 [NC,L]

The following URL's would all match:

http://example.com/30/about_our_company
http://example.com/29/contact
http://example.com/10/our_work

since /about_our_company doesn't include the ID, it's impossible to invent the ID correctly.

the way I do it in my own CMS is to have something like this in the .htaccess:

RewriteEngine on
RewriteRule ^(.*)$ /index.php?page=$1 [QSA,L]

then in index.php, use the $_REQUEST['page'] (assuming PHP) variable to find the right page details in the database

此ofc的固定标识为30

RewriteRule ^about_our_company/?$  /page.php?name=$1&id=30 [NC,L]

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