简体   繁体   中英

Seo URL - htacces rewrite rules

I need to rewrite some urls:

In php they are designed like: www.example.com/product.php?id=1

Someone helped me to rewrite them to: www.example.com/product/1/casual-shoe/

Now I found that is not recommended for SEO.

And I need to transform the link in something like:

www.example.com/casual-shoe/ShoeNickname`

I don't know from where to begin.

I will make in mysql a new column for ShoeNickname equivalent to each id.

Is there anyone who can tell me how to write the .htacces file?

I assume that in this example `casual-shoe' is the category and you sell many casual shoes.

The easiest was to solve this is to keep id in the URL, while ignoring the other information, like www.example.com/casual-shoe/23-converse-all-stars

The .htaccess would be something like

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

The 2 RewriteCond lines tell to only rewrite if the requested url doesn't match a real file. Next you rewrite anything with a (category) directory followed by a filename starting with 1 or more decimals, followed by a dash and more text.

The decimals are the product ID, the rest of the URL is simply ignored.

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