Jump to content

Make URL's more friendly


sphinx

Recommended Posts

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

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.

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.

  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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.