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! Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
xyn Posted July 4, 2007 Share Posted July 4, 2007 updated, last post. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 4, 2007 Share Posted July 4, 2007 Cheers wildteen you a star. Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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? Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment 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.