| | |
mod_rewrite and PHP problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 2
Reputation:
Solved Threads: 0
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
to be rewritten as
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
And in my index.php I have the following PHP to read the converted url.
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!
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=image1to be rewritten as
www.mysite.co.uk/page1/image1I'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
PHP Syntax (Toggle Plain Text)
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.
PHP Syntax (Toggle Plain Text)
$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!
•
•
Join Date: Nov 2007
Posts: 86
Reputation:
Solved Threads: 6
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.
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
PHP Syntax (Toggle Plain Text)
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
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
$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["..."]
$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.
![]() |
Similar Threads
- multiple variables in a mod_rewrite URL string (Linux Servers and Apache)
- php and mod_rewrite problem (PHP)
- mod_rewrite related problem (Linux Servers and Apache)
- vBulletin mod_rewrite (PHP)
- vBulletin mod_rewrite for vB 3.0.7 (Existing Scripts)
- PHP as Apache module vs CGI (Linux Servers and Apache)
- Apache mod_rewrite with Google Ads (Linux Servers and Apache)
- Using Search Engine Friendly PHP URLs (PHP)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: date function
- Next Thread: error jump to row 0
Views: 638 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms soap source space speed sql static structure syntax system table tutorial up-to-date update updates upload url validation validator variable video web wordpress xml youtube





