简体   繁体   中英

Shorten URL for htaccess

I am editing a code for making my url short but there is a problem with it had to have two variable so that it can be found in server? The code i create is like this:

RewriteRule product/([^/\.]+)/([^/\.]+)/?$ product_info.php?ItemName=$1&uid=$2

result:

http://Example.com.my/product/NBR/901003-7

if the uid is being taken out the url will become error and show that file could not be found. is it about the htaccess code or the php code that cause this problem.

the url that i hope to get is this: http://Example.com.my/product/NBR

You can set up 2 different Rewrite rule in the .htacess file

  1. Rewrite rule if you have uid in your URL

    RewriteRule product/([^/] )/([^/] )$ product_info.php?ItemName=$1&uid=$2

  2. Rewrite rule if you do not have uid in your URL

    RewriteRule product/([^/])$ product_info.php?ItemName=$1

Here is the screenshot:

With UID

在此处输入图片说明

Without UID

在此处输入图片说明

.htacess code

在此处输入图片说明

Hope it works for you.

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