Joshua4550 Posted May 24, 2010 Share Posted May 24, 2010 Hey guys, First off, I want to say i'm not sure if this was the right section, but it seemed most appropriate (if what i'm looking for is a PHP application, anyway) The title was the most relevant way I could put it, but his is what i'm looking for: An application which can convert your URL, so say for example a URL on my site was: http://www.example.com/?thing=this Then the application would convert the URL to: http://www.example.com/thing/this I'm sure i've seen this application advertised somewhere before, I just forgot what is was called! Please respond, thanks Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/ Share on other sites More sharing options...
kenrbnsn Posted May 24, 2010 Share Posted May 24, 2010 This is done with rewrites in an .htaccess file, so I'm moving it to the correct location. (moving from PHP Applications) Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062740 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Any idea how? Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062741 Share on other sites More sharing options...
cags Posted May 24, 2010 Share Posted May 24, 2010 First flip your perspective on your head, the way your application should work is all links on your site should be change to be http://www.example.com/thing/this, then once this is done you use mod_rewrite to rewrite that style of url to the other style (http://www.example.com/?thing=this). Therefore you pages should be coded to work the way it probably currently does (i.e with http://www.example.com/?thing=this links), however all links on your page should be the other type. A simple example of how a RewriteRule... RewriteRule ^([^/]+)/([^/]+)/?$ /?$1=$2 Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062743 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Okay, well my main aim to use this for is for the following: converting- site.com/site.php?s=ANYTHINGHERE to- site.com/ANYTHINGHERE (And maybe the opposite way around too, so they can type either one) I'm guessing this cannot be too difficult? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062744 Share on other sites More sharing options...
cags Posted May 24, 2010 Share Posted May 24, 2010 RewriteRule ^(.*)$ /site.php?s=$1 Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062745 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Thanks. Is there anything I need to include before that in the .htaccess file? (I read other things on tuorials around the web) Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062746 Share on other sites More sharing options...
cags Posted May 24, 2010 Share Posted May 24, 2010 You will also need... Options +FollowSymLinks RewriteEngine on Bare in mind this will forward ALL requests to your site to that page, this will likely screw up all css/images/js files on your site, so this is something to take into account also. Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062748 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Oh, I thought reqriting worked both ways... In which case, what I actually needed was site.com/USERNAME to send them to site.com/site.php?s=USERNAME Would the concept be the same? And/or still easy? Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062750 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Oh, and on the redirection - to avoid image/js/css collision, I could just redirect from a URL which doesnt exist, such as site.com/site/WHATEVERHERE which redirects to site.com/site.php?s=WHATEVERHERE This will stopp the collision with css/js/imgs won't it? Since the directory /site doesn't actually exist, it's just what the users will type Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062752 Share on other sites More sharing options...
cags Posted May 24, 2010 Share Posted May 24, 2010 Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^(.*)$ /site.php?s=$1 Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062753 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Sorry, i'm REALLY new to this - so PLEASE excuse me. I'm probably going to research some tomorrow, but it's late atm. What exactly would that one do? Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062755 Share on other sites More sharing options...
cags Posted May 24, 2010 Share Posted May 24, 2010 Redirect all URLs that are not files or directories on the server to that address. Since usernames probably use a specific character set you would really want to be more specific, but it should get you started. Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062757 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Okay thanks - but one thing. What about if I wanted to do it so they have to put the username after /site such as site.com/site/USERNAME Because i'm guessing i can't just stick /site/ infront of the RegEx? Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062758 Share on other sites More sharing options...
cags Posted May 24, 2010 Share Posted May 24, 2010 Yes, but without the first forwardslash. Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062762 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Okay, but it seems to not work. Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule site/^(.*)$ /site.php?s=$1 http://site.com/site/hi Not Found The requested URL /site/hi was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062763 Share on other sites More sharing options...
cags Posted May 24, 2010 Share Posted May 24, 2010 The site/ needs to be after the ^ as the ^ character anchors the start of the string. Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062765 Share on other sites More sharing options...
Joshua4550 Posted May 24, 2010 Author Share Posted May 24, 2010 Works a charm! Thank you very much, thanks for being so calm and understanding, and for helping me! Quote Link to comment https://forums.phpfreaks.com/topic/202773-url-conversion/#findComment-1062770 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.