user3000993
user3000993

Reputation: 55

how to remove in url two get id

now my url is

detail.php?category=abc&model=126

and i want like this

detail/abc-126.html

and i am using this code in but it is not working properly

.htaccess

RewriteRule ^detail/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ detail.php?category=$2&model=$2

and my 2nd question is suppose if i use a dir like this in my website foldername

www.example.com/foldername/detail/abc-126.html

and my php file in this folder

www.example.com/foldername/detail.php

and my .htaccess file in

www.example.com/.htaccess 

is here

so how can i use with foldername

and this is not a duplicate post i search many sites but i did not understand how to solve this

so please help me to fix this issue thanks

Upvotes: 0

Views: 58

Answers (2)

Rasclatt
Rasclatt

Reputation: 12505

You have two conditions and you are referencing $2 twice instead of $1 & $2. So that is one problem. That probably won't solve your issue because I am not very good at rewrites, but it's a start.

Also you are wanting abc-126.html but you have a forward slash in between your rewrite like so )/(.

For your second question, I am not 100% sure what you are asking, but if the .htaccess file is in the parent directory, it's effect is felt through the children directories unless you put a new .htaccess file in the child directory.

Upvotes: 1

Sverri M. Olsen
Sverri M. Olsen

Reputation: 13283

You are capturing two things, $1 and $2. When you create the path that it should be redirected to you only use $2. You have to use both of them in order for this to work:

                                          .-------------------------------------.
                            .------------/------------------------------.        \
                    |----- $1 -----| |- $2 -|                            \        \
RewriteRule ^detail/([a-zA-Z0-9_-]+)-([0-9]+)\.html$ detail.php?category=$1&model=$2

Upvotes: 1

Related Questions