sphinx Posted May 20, 2013 Share Posted May 20, 2013 (edited) Hello. I'm currently using isset. So my links look like: http://site.com/?1 http://site.com/?2 etc etc.. Instead of a layout like that, can .htaccess be used to make the same link load but have the URL as: http://site.com/1 http://site.com/2 etc etc.. Thanks Edited May 20, 2013 by sphinx Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/ Share on other sites More sharing options...
PravinS Posted May 20, 2013 Share Posted May 20, 2013 yes using .htaccess (RewriteRule) you can set urls according to your requirement Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1431131 Share on other sites More sharing options...
sphinx Posted May 21, 2013 Author Share Posted May 21, 2013 (edited) I've tried using this: RewriteEngine on RewriteCond %{HTTP_HOST} =example.co.uk [OR] RewriteCond %{HTTP_HOST} =www.example.co.uk RewriteCond %{REQUEST_URI} !^/?$ [NC] RewriteRule ^ http://example.co.uk?%{REQUEST_URI} [R=301,L] However, if I do: http://example.co.uk/test It redirects to: http://example.co.uk/?/test/ I need it to redirect like: http://example.co.uk/?test Thanks Edited May 21, 2013 by sphinx Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1431339 Share on other sites More sharing options...
DaveyK Posted May 21, 2013 Share Posted May 21, 2013 RewriteEngine on RewriteCond %{HTTP_HOST} =example.co.uk [OR] RewriteCond %{HTTP_HOST} =www.example.co.uk RewriteCond %{REQUEST_URI} !^/?$ [NC] RewriteRule ^ http://example.co.uk?$1 [R=301,L] Try that. I am really just guessing but I use $1 in my htaccess. Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1431341 Share on other sites More sharing options...
xenLiam Posted May 23, 2013 Share Posted May 23, 2013 (edited) Try this (I'm no expert on this myself, but it's worth a shot) (Edited) RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)$ /?$1 In theory, that should make http://site.com/1 be the equivalent of http://site.com/?1. Also, I didn't set it so that it would redirect URLs with /?1 to /1 and vice versa. Also worth noting is that you have to change / to the path of your URL. Note: Edited it to work with words and numbers + tested. Edited May 23, 2013 by xenLiam Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1431792 Share on other sites More sharing options...
jazzman1 Posted May 24, 2013 Share Posted May 24, 2013 (edited) @Liam, how achived that without using a redirect flag? Can you show us your personal testing, please Edited May 24, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1432076 Share on other sites More sharing options...
jazzman1 Posted May 24, 2013 Share Posted May 24, 2013 @DaveyK, do you understand that script or you just copy/paste it from the web? Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1432080 Share on other sites More sharing options...
xenLiam Posted May 25, 2013 Share Posted May 25, 2013 @Liam, how achived that without using a redirect flag? Can you show us your personal testing, please It's a rewrite rule, not a condition, so I don't think it needs any more flags, although I may be wrong, as I am not an expert in rewrites. I managed to test it by placing an index.php file in the root of my localhost LAMP server and inside the index.php I wrote: <?php if(!empty($_SERVER["QUERY_STRING"])) { echo $_SERVER["QUERY_STRING"]; } ?> ... and it seems to work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1432197 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.