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

Edited by sphinx
Link to comment
Share on other sites

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
Share on other sites

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 by xenLiam
Link to comment
Share on other sites

@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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.