0

i am trying to rewrite URL using htaccess. i need

1>   temp.example.com/save.php?item=xxxxx&id=xxx&type=1 
2>   temp.example.com/save.php?item=xxxxx&id=xxx&type=2 

to be like

1>   temp.example.com/save/xxxxx/xxx
2>   temp.example.com/save/xxxxx/xxx

have to hide last parameter .

my htaccess has

RewriteCond %{THE_REQUEST} \s/save\.php\?item=([_0-9a-zA-Z-]+)\s&id=([_0-9a-   zA-Z-]+)\s&type=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^temp/save/%1/%2/%3? [R=301,L]
RewriteRule ^temp/save/([_0-9a-zA-Z-]+)$/([_0-9a-zA-Z-]+)$/([_0-9a-zA-Z-]+)$ /save.php?item=$1&id=$2&type=$3 [L] 

Thanks

3
  • Why do you not want type parameter's value in temp.example.com/save/example/2? Do you always want type=1 to be statically added to save.php? Commented Jan 29, 2015 at 6:53
  • yes type is kind of static, that's why no need to show Commented Jan 29, 2015 at 6:55
  • You cannot hide type now since it is not static anymore as it has value 1 and 2 that you will need in save.php Commented Jan 29, 2015 at 7:23

2 Answers 2

1

You can use these rules in root .htaccess:

RewriteCond %{THE_REQUEST} /save\.php\?item=([^\s&]+)&id=([^\s&]+)&type=([^\s&]+)\s [NC]
RewriteRule ^ save/%1/%2/%3? [R=302,L]

RewriteRule ^save/([\w-]+)/([\w-]+)/([\w-]+)/?$ save.php?item=$1&id=$2&type=$3 [L,QSA,NC]
Sign up to request clarification or add additional context in comments.

6 Comments

i have my code in sub domain . this will work for temp.example.com ?
That means you didn't place it in root .htaccess. See updated rule. I have already tested it and it worked fine for me on my Apache.
I have already tested it from root ,htaccess and it worked fine. Make sure you have just these 2 rules when you test it.
and sir, type can be type=1 or type=2
I don't get that question, you only replied that type is kind of static so put whatever static value here.
|
0

RewriteEngine On

RewriteRule ^save.php/([a-zA-Z0-9_-]+)/(.)/(.)$ /save.php?id=$1&order_id=$2&page_no=$3 [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php

now you can access three parameter by pass like temp.example.com/save/par1/par2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.