1

I am new to URL rewrite, regex and .htaccess

Here is an issue I am facing:

I have this url with GET parameter: www.mysite.in/alpha-beta/abc.php?id=APPLE%strike=200.00

I want to display it like: www.mysite.in/alpha/beta/APPLE/200.00

This is the code in .htaccess:

RewriteRule ^alpha/beta/(.*)/([0-9]+(\.[0-9]+))$ alpha-beta/abc.php?id=$1&strike=$2 [NC,L]

But I only get a blank page when I go to URL: www.mysite.in/alpha/beta/APPLE/200.00

When I change the htaccess rule to:

RewriteRule ^alpha/beta/(.*)/([0-9]+(\.[0-9]+))$ http://www.mysite.in/alpha-beta/abc.php?id=$1&strike=$2 [NC,L]

It redirects to correct page but the URL is displayed as http://www.mysite.in/alpha-beta/abc.php?id=APPLE&strike=200.00

What seems to be the problem?

5
  • Added new information. Perhaps this will help. Commented Aug 3, 2015 at 7:34
  • You could be right. I haven;t dome any changes/ addition to rewritten URL? can you give some more information on what additional css/js should be there for the purpose of rewriting? Commented Aug 3, 2015 at 7:46
  • This one is with absolute link in htaccess: niftytrader.in/OI_TOOL/LTP/ADANIPORTS/300.00 and this is with relative link in htaccess: niftytrader.in/OI_TOOL/IV/ADANIPORTS/300.00 Commented Aug 3, 2015 at 8:12
  • It is because http://www.niftytrader.in/OI_TOOL/IV/ADANIPORTS/300.00 is unable to load your getIV.php via jquery and results in 404. Commented Aug 3, 2015 at 17:17
  • Do you know any way around this? iv_chart.php is fetching data from getIV.php Commented Aug 3, 2015 at 18:51

1 Answer 1

2

Use these rules in root .htaccess:

RewriteEngine On

RewriteRule ^OI_TOOL/IV/(.*)/([0-9]+(?:\.[0-9]+))/?$ OI_ANALYSIS_TOOL/iv_chart.php?symbol=$1&str‌​ike=$2 [NC,L,QSA]

# fix path for getIV.php by redirecting it to /OI_ANALYSIS_TOOL/
RewriteRule ^OI_TOOL/.+?/(getIV\.php)$ /OI_ANALYSIS_TOOL/$1 [L,NC,R=301]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. It's working perfectly. Though It will take me a while to understand it :) Cheers
Just one more issue. The same 2 parameters are being passed to getIV.php but I think the above solution is only passing one parameter. could you suggest the changed version?
niftytrader.in/OI_TOOL/OI/ADANIPORTS/330.00 and niftytrader.in/OI_ANALYSIS_TOOL/… should show same results but its not same. the first link is showing result for strike=0.00 (it seems)
That is due to your own code inside drawChart function that you need to fix.
Sorry, it was a mistake. I was just browsing thru this question and clicked unintentionally. How do I revert it?

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.