PDA

View Full Version : PHP Mod_Rewrite Help


Relemente
10-11-2004, 06:25 AM
I've read quite a bit of threads on how to rewrite the URL but none seem to have gotten me anywhere.

I basically want to make a URL

http://mydomain.com/file.php?typeid=1

into

http://mydomain.com/file/typeid/1

and also

http://mydomain.com/file.php?typeid=1&otherid=2

into

http://mydomain.com/file/typeid/1/otherid/2

I read this thread http://forums.searchenginewatch.com/showthread.php?t=95

But it doesnt seem to be working for me.
Also I am using a host with CPanel so I dont know if the RewriteBase is right.
I am pretty sure the module is installed because I could rewrite a http://domain.com to http://www.domain.com

Thanks in advance for the help!

Nick W
10-11-2004, 07:01 AM
Hi, and welcome!

It's not so tough ;-)

First, name your file file - no .php extention

If you are running apache 1.3x then put this in your .htaccess


<Files file>
ForceType application/x-httpd-php
</Files>

This will force apache to look at file as a php file.

then in file:


$vars = explode('/', $_SERVER['PATH_INFO']);
print_r($vars);


NB: things have changed with both apache and php since i last did this - you may need to use PATH_TRANSLATED instead of PATH_INFO and you may need to put AcceptPathInfo = On in your .htaccess

this page:
http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server

Is where you can find the relevant environment vars for your setup, you'll clearly have to experiment a little as I dont have time to test :(

Nick

grnidone
10-14-2004, 08:17 PM
Nick_W

I feel like this may be a dumb question, but why do you want your mod_rewrite file to be seen as a php file instead of just editing the .htaccess file to have the necessary regular expressions to do the apache_rewrite?

I've never heard of making the .htaccess readable as a php file and I guess I just don't understand why you'd want to do it.

What are the benefits?