andreasb Posted November 6, 2009 Share Posted November 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/ Share on other sites More sharing options...
cags Posted November 7, 2009 Share Posted November 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/#findComment-953088 Share on other sites More sharing options...
mga_ka_php Posted November 7, 2009 Share Posted November 7, 2009 there's a problem when adding a trailing slash at the end. the images and css doesn't load. it might think that it is a folder Quote Link to comment https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/#findComment-953126 Share on other sites More sharing options...
cags Posted November 7, 2009 Share Posted November 7, 2009 Since the Rule rewrites to the same address, regardless of the slash I don't see how it would make any difference Quote Link to comment https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/#findComment-953130 Share on other sites More sharing options...
mga_ka_php Posted November 9, 2009 Share Posted November 9, 2009 but i am having a problem about that. when i try to add "/" at the end. you can only see the text. the format and images is not loaded. any solution for that? Quote Link to comment https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/#findComment-953989 Share on other sites More sharing options...
cags Posted November 9, 2009 Share Posted November 9, 2009 Without seeing your script it's difficult to say. Quote Link to comment https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/#findComment-954037 Share on other sites More sharing options...
andreasb Posted November 9, 2009 Author Share Posted November 9, 2009 OK - I'll take a look at this, and I think that a friend of mine might be able to help. I'll post my code here if he can't help me any further. Quote Link to comment https://forums.phpfreaks.com/topic/180609-mod_rewrite-url-rewrite-question/#findComment-954327 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.