0

I am new in writing url rewrite rules. Can you help me in writing rewrite rules. My current browser url is

http://localhost/live/match-page.php?mid=770&sid=7

My anchor tag for that url is given below

<a target='_blank' href="match-page.php?mid=<?php echo $rec->ID?>&sid=<?php echo $rec->stream_id?>" style="color:#ffae00;">  <?php echo $rec->CatName; ?> - <?php echo $rec->Title; ?> </a>

How I edit .htaccess file then I show my browser url like given bellow here:

http://www.cricmelive.tv/live/177/south-africa-v-india-test-live-streaming
http://www.cricmelive.tv/live/Basketball-live-streaming

how make anchor tage for url rewrite mode?

It is true that I made new queries for it? And pass to the database. If it is possible how do it.

2
  • Do you need both mid and sid Commented Dec 9, 2015 at 10:20
  • yes I need both @AbhishekAgrawal Commented Dec 9, 2015 at 10:27

3 Answers 3

1

I hope these help. I'm a little confused though, you say you need both mid & sid yet the examples above are different ~ one has both the mid and sid parameters yet the other only has one, presumably sid

#htaccess

RewriteEngine On
RewriteBase /

RewriteRule ^live/(.+)$ live/match-page.php?sid=$1 [NC,L]
RewriteRule ^live/([0-9]+)/(.+)$ live/match-page.php?mid=$1&sid=$2 [NC,L]


/* php */
/* Match first style rewrite rule */
echo "<a target='_blank' href='/live/{$rec->stream_id}' style='color:#ffae00;'>  {$rec->CatName} - {$rec->Title} </a>";

/* match second style rewrite rule */
echo "<a target='_blank' href='/live/{$rec->ID}/{$rec->stream_id}' style='color:#ffae00;'>  {$rec->CatName} - {$rec->Title} </a>";

There are two ways in which you can use urlrewrite - one as shown here where you generate your links as shown to match the pattern set in the rewrite rule and the other method is to use the links as you had them originally and use apache to make the ugly querystring into the new, pretty url. For examples of how to do the latter, have a look at some of the posts by Anubhava ~ he is a master!

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

2 Comments

let me try it. @RamRaider
In case original url basic links every thing ok as see in print scr: (prntscr.com/9ceyxw) but in url rewrite code, I think don't apply css file why, check in print scr: (prntscr.com/9cf09d) where my url-rewrite code is : RewriteRule ^([0-9]+)/([0-9]+)/(.+)$ match-page.php?mid=$1&sid=$2 [NC,L] its work fine @RamRaider
0

What you are asking is how can you replace your current url patterns with a cleaner scheme (clean urls).

Your match page logic behind the scenes is most likely using 'mid' and 'sid' to do some kind of database lookup for the results.

Minimal change could be to change to a new url format like this:

http://www.example.com/live/MID/SID/text-descriptor
http://www.example.com/live/770/7/south-africa-v-india-test-live-streaming

.htaccess

RewriteEngine On
RewriteRule ^live/([0-9]+)/([0-9]+)/ match-page.php?mid=$1&sid=$2 [L]

Then change your links to output the new pattern:

$href = '/live/' . $rec->ID . '/' . $rec->stream_id . '/' . $rec->text; // text from category or title (isn't needed by script.)

7 Comments

In case original url every thing ok as see in print scr: [link](prntscr.com/9ceyxw) but in url rewrite code, I think don't apply css file why, check in print scr [link](prntscr.com/9cf09d) @Progrock why? thanks to reply
@mc120400429 , probably because you are using relative URL paths for the CSS. So the browser is likely trying to now find the CSS in /live/123/456/ or similar (check browser tools/network/assets). Change your CSS path to an absolute from the root of your site. So instead of 'css/site.css' use '/css/site.css'.
thanks to reply @Progrock, you guess right, I check it from tools/network/css status code is ok 200 and relative path is wrong path (localhost/live/330/4/templatemo_style.css). I change it templatemo_style.css to /templatemo_style.css but its not response how do it? I am sending you screen shot for it. see in print screen shot
Given your path above: /tools/network/css/templatemo_style.css.
yes? what mean that path /tools/network/css/templatemo_style.css ? I check it with Inspect element from broswer I put it as but not work
|
0

Add this code to htaccess file

 Options -MultiViews +FollowSymLinks
 RewriteEngine On
 RewriteRule ^/?live/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /match-page.php?mid=$1&sid=$2 [L]

On match-page.php, you can get mid and sid, assuming you add url like http://www.cricmelive.tv/live/770/7/Basketball-live-streaming

EDIT

Add this code to htaccess file

 Options -MultiViews +FollowSymLinks
 RewriteEngine On
 RewriteRule ^/?live/([0-9]+)/([0-9]+)/?$ /match-page.php?mid=$1&sid=$2 [L]

11 Comments

Then how make anchor tage for it? @RamRaider in match-page.php file to create link for it.
@mc120400429 is this comment for me?
oh I can understand, let me try for it @Abhishek Agrawal
no it for RamRaider by mistake I past it here @Abhishek Agrawal
I try with your both code, put into the htaccess file and hit the browser with url: localhost/live/770/7/Basketball-live-streaming. it does not work @Abhishek Agrawal
|

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.