Jump to content

Mod_rewrite / URL Rewrite question!


andreasb

Recommended Posts

Hello!

Let's say I'm creating a web site where a (example) URL looks like this:

www.somesite.com/movie.php?id=tt0417741

 

Is there a way I could rewrite this URL, and all the other URLs that looks like that (but with other ID number/IMDB number) to this?:

www.somesite.com/tt0417741/

 

The website is database driven.

Can this be done with htaccess? In that case, how?

Link to comment
https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/
Share on other sites

Simple answer.... No (and Yes). Like pretty much everybody, you've got the concept of 'rewritting' backwards. You don't rewrite your first example to your second, you rewrite your second example to be your first. The rewritting process involves taking the URL entered by the user and rewritting it to the URL you wish your server to actually run. In it's simplest form, you would be looking at something along the lines of this...

 

Options +FollowSymLinks  
RewriteEngine On  

RewriteRule ^(.+)/?$ /movie.php?id=$i

 

If you wish to validate the data abit more you might for example have...

 

Options +FollowSymLinks  
RewriteEngine On  

RewriteRule ^([a-z]{2}[0-9]{7})/?$ http://www.google.com?id=$1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.