0

I am new on .htaccess and want to redirect URL from .htaccess

like:

http://test.example.com/abc/xyz/456adf646asdf

to

http://test.example.com/abc/xyz?id=456adf646asdf

or http://test.example.com/abc/xyz/?456adf646asdf

Please help.

I tried this:

RewriteRule ^(.+)/abc/xyz/$ /abc/xyz?id=$1

but did not work for me..

5
  • didn't you tried anything? Commented Jul 16, 2013 at 12:57
  • I tried, but did not work for me..RewriteRule ^(.+)/ride/linkedin/$ /ride/linkedin?id=$1 Commented Jul 16, 2013 at 13:00
  • edit your question and update with your example Commented Jul 16, 2013 at 13:00
  • done. please check question. Commented Jul 16, 2013 at 13:02
  • try RewriteRule ^/ride/linkedin/(.+)$ /ride/likedin?id=$1 Commented Jul 16, 2013 at 13:09

2 Answers 2

1

You should also have a RewriteCond to match the incoming URL pattern. Try this to match you explicit case.

 RewriteCond %{REQUEST_URI} ^/abc/xyz/(.\*)
 RewriteRule (.\*) /abc/xyz?id=%1 [L]

There are of course lots of options. You could also try

  RewriteCond %{REQUEST_URI} ^/(.\*)/(.\*)/(.\*)  
  RewriteRule (.\*) /%1/%2?id=%3 [L]

Where %1 would match 'abc', %2 would match 'xyz', and %3 456adf646asdf in your example.

Is mod_rewrite installed?

Sign up to request clarification or add additional context in comments.

5 Comments

this is working but not show id... staging.rdfs.in/ride/linkedin/?id=
Please post back the Rewrite rule you used.
Thank you for formatting the code. Just joined yesterday, that's my next lesson.
Thanks, Mr. Tanstaafi and Mr. AKAM for response but this error show after both changes "The requested URL /abc/xyz/232323asf was not found on this server."
try this: RewriteCond %{REQUEST_URI} ^/abc/xyz/(.*)/ RewriteRule (.*) /abc/xyz?id=%1 [L] with url: example.com/ride/linkedin/12122/
0

That won't work. Try this:

RewriteRule ^/abc/xyz/(.+)$ /abc/xyz?id=$1

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.