Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.