goddamnyouryan
goddamnyouryan

Reputation: 6896

Clean URLs in PHP without mod_rewrite

I am developing a backend for a site I built for a client in PHP (which I rarely use), which is almost completed. I'm a Rails developer primarily, so I'm having a hard time not going for some bastardized version of a CRUD setup, and I am attempting to clean up the urls.

I would like my urls to be like so:

http://www.example.com/videos/name-of-video/

I plan on just taking the last bit of the url from $_SERVER['PHP_SELF'] and searching through the DB using that, but what I would like to do is throw the index.php file in the http://www.example.com/videos/ directory and have it be used when I explicitly point someone to http://www.example.com/videos/name-of-video/, if that makes sense.

Will this work as is, if I put the index.php in the /videos/ directory, or is something else needed? Is it possible to do without messing around with htaccess?

Sorry for my pathetic explanation. I hope it makes sense.

Thanks!

Upvotes: 2

Views: 1935

Answers (2)

mario
mario

Reputation: 145482

There are a few options to do it without a RewriteRule. Not without .htaccess messing.

First you can name a PHP script without extension, that is video instead of video.php, and then set the actual file type via ForceType or DefaultType. So the PHP interpreter will still pick it up. The path will show up in $_SERVER['PATH_INFO'

Likewise would an enabled +MultiViews allow a PHP script not to have an extension.

And lastly an ErrorDocument handler can be used in place of a real RewriteRule. It brings any number of drawbacks with it however.

An index.php by itself will not pick up any random filenames in a fake path. The only option for that to work is using URLs like http://www.example.com/videos/?name-of-video/

So no. No nice URLs with directory mimicking without some configuration.

Upvotes: 3

Jigar Tank
Jigar Tank

Reputation: 82

As per my knowledge this manipulation is not possible without touching .htaccess. when you write the url http://www.example.com/videos/name-of-video/ your server is definitely going to look for the index.php file in the folder name-of-video folder. which does not exist.

If this task could have been achieved without .htaccess then they would have never been used. And by the way why don't you want to use .htaccess..??

Upvotes: 2

Related Questions