sandrob57 Posted July 4, 2007 Share Posted July 4, 2007 How do I turn a url like this: myfancyurl.com/user/profile.php?lookup=321 into this: myfancyurl.com/user/321 Hmm? This possible with PHP? HALP! Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/ Share on other sites More sharing options...
xyn Posted July 4, 2007 Share Posted July 4, 2007 Mod Rewrite; Basically in your root directory... make a file called .htacess. .htaccess # Rewrite Mod RewriteEngine on RewriteBase / RewriteRule ^user/(.*)$ myfancyurl.com/user/profile.php?lookup=$1 [L] ok here it is: RewriteEngine on ; turn the engine on RewriteBase / ; set the root directory. RewriteRule ^user/(.*)$ myfancyurl.com/user/profile.php?lookup=$1 ^ = start (.*) = userid as a variable $ = end of match. then $1 = value of (.*). And i forgot. [L] = last action So you now make your links. /user/192643 Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-289761 Share on other sites More sharing options...
xyn Posted July 4, 2007 Share Posted July 4, 2007 updated, last post. Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-289765 Share on other sites More sharing options...
redarrow Posted July 4, 2007 Share Posted July 4, 2007 xyn love the given example. I am studying mod_rewrite can you kindly tell me if you use a regular exspristion in mod_rewrite the regulalr exsprision is the same as what eregi or preg dont get it cheers. If you could write your example but with the correct regular exspression please. Sorry to but in cheers. Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-289775 Share on other sites More sharing options...
wildteen88 Posted July 4, 2007 Share Posted July 4, 2007 Yes you use regular expressions within mod_rewrite. The regex syntax is the same as PHP's Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-289782 Share on other sites More sharing options...
redarrow Posted July 4, 2007 Share Posted July 4, 2007 Cheers wildteen you a star. Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-289784 Share on other sites More sharing options...
redarrow Posted July 4, 2007 Share Posted July 4, 2007 # Rewrite Mod RewriteEngine on RewriteBase / RewriteRule ^[a-z]{0,10}\/\(\.\*\)\.(html)\$[a-z}{1,10}\. [a-z]{0,3}\/[a-z]{1,4}\/[a-z]{0,10}\.[a-z{0,3}\?[a-z]{0,10}\=\$1 [L] now if i am write now you can have the url /user/192643.html now you can get in the seach engine as friendly. Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-289800 Share on other sites More sharing options...
sandrob57 Posted July 5, 2007 Author Share Posted July 5, 2007 Thank you so much! This community rules! Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-290076 Share on other sites More sharing options...
sandrob57 Posted July 6, 2007 Author Share Posted July 6, 2007 ok problem. all the images on the page dont load, and the page takes reaaaaly long to load. I think it is messing with the URL's in the images...how do I stop this? Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-291045 Share on other sites More sharing options...
sandrob57 Posted July 6, 2007 Author Share Posted July 6, 2007 this is my exact code (i would have edited my previous post but it wont let me) # Rewrite Mod RewriteEngine on RewriteBase / RewriteRule ^user/(.*)$ /profile.php?lookup=$1 [L] Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-291055 Share on other sites More sharing options...
corbin Posted July 6, 2007 Share Posted July 6, 2007 Well, you're at user/ so if you're trying to access images/ and it's in the folder below, then it's not going to find it ;p. Link to comment https://forums.phpfreaks.com/topic/58436-neat-url/#findComment-291068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.