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

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^([^/]*)$ /index.php?id=$1 [R]
RewriteRule ^([^/]*)/([^/]*)$ /index.php?id=$1&idimg=$2 [R]

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

$data = explode("/",$HTTP_SERVER_VARS['PATH_INFO']);
	$id = $data[1];
	$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!

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.

RewriteEngine on
RewriteRule ^([a-z0-9_]+)$ /$1/ [nc]
RewriteRule ^([a-z0-9_]+)/?$ index.php?name=$1 [nc]
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
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

$data = explode("/",$HTTP_SERVER_VARS);
$id = $data[1];
$idimage= $data[2];

i think you don't have to do this. you simply get your values using $_GET["..."]

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.