mod_rewrite and PHP problem

Reply

Join Date: Mar 2008
Posts: 2
Reputation: andrewcross is an unknown quantity at this point 
Solved Threads: 0
andrewcross andrewcross is offline Offline
Newbie Poster

mod_rewrite and PHP problem

 
0
  #1
Mar 11th, 2008
Hi, this is driving me crazy so hope you can help. It seems quite simple.
Basically I have a simple site consisting of an index.php page that loads in the other pages using php switch case. This all works great. The trouble I'm having is cleaning the url with mod_rewrite

I'd like

www.mysite.co.uk/index.php?id=page1&idimage=image1

to be rewritten as

www.mysite.co.uk/page1/image1

I've tried using several mod_rewrite variations but nothing happens or I get error 500. The mod-rewrite is working fine when I did a test to remove "www". Can't figure this out! The .htaccess code I've tried is
  1.  
  2. Options +FollowSymlinks
  3. RewriteEngine on
  4.  
  5. RewriteRule ^([^/]*)$ /index.php?id=$1 [R]
  6. RewriteRule ^([^/]*)/([^/]*)$ /index.php?id=$1&idimg=$2 [R]

And in my index.php I have the following PHP to read the converted url.

  1.  
  2. $data = explode("/",$HTTP_SERVER_VARS['PATH_INFO']);
  3. $id = $data[1];
  4. $idimage= $data[2];

I know people have asked about this before but I just can't get this working!! I've read loads of tutorials, but to no avail!

Please help! Before I throw my computer out the window!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: mod_rewrite and PHP problem

 
0
  #2
Mar 12th, 2008
Here is my mod rewrite, it should work for you, all you need to do is change mydomain.com to your actual domain, everywhere that you see it.
  1. RewriteEngine on
  2. RewriteRule ^([a-z0-9_]+)$ /$1/ [nc]
  3. RewriteRule ^([a-z0-9_]+)/?$ index.php?name=$1 [nc]
  4. RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
  5. RewriteCond %{HTTP_HOST} ^www.mydomain.com$
  6. RewriteRule ^/?$ http://www.mydomain.com/home

Basically, you are making sure that the url has a trailing slash, then you are rewriting everything that hase index.php?name=something to www.mydomain.com/something
note lines four and five... these conditions make this true wether or not there is a www or not in the url.

This should allow you to do what you want.
HTH
Sage
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: mod_rewrite and PHP problem

 
0
  #3
Mar 12th, 2008
$data = explode("/",$HTTP_SERVER_VARS['PATH_INFO']);
$id = $data[1];
$idimage= $data[2];

i think you don't have to do this. you simply get your values using $_GET["..."]
Last edited by silviuks; Mar 12th, 2008 at 12:47 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: andrewcross is an unknown quantity at this point 
Solved Threads: 0
andrewcross andrewcross is offline Offline
Newbie Poster

Re: mod_rewrite and PHP problem

 
0
  #4
Mar 12th, 2008
Thanks for your reply, I've tried your mod_rewrite but unfortunately it didn't work, nothing changed. I'm wondering if it's another problem alltogether, but I wouldn't have a clue where to look.

Cheers guys.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 638 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC