sphinx Posted May 20, 2013 Share Posted May 20, 2013 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 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 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 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 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. 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 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. 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 @Liam, how achived that without using a redirect flag? Can you show us your personal testing, please 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? 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 On 5/24/2013 at 2:26 PM, jazzman1 said: @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. Link to comment https://forums.phpfreaks.com/topic/278197-make-urls-more-friendly/#findComment-1432197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.