Simple SEO rewrite using htaccess - SOLVED

18 posts by 4 authors in: Forums > CMS Builder
Last Post: May 5, 2010   (RSS)

By (Deleted User) - April 20, 2010

The original page is:

http://www.mywebsite.co.uk/conditions.php?detailpage-1

with this code at the top:
<?php
$location = "/conditions/".$_SERVER['QUERY_STRING'].".html";
header("Location:$location");
?>


It changes to:
http://www.mywebsite.co.uk/conditions/detailpage-1.html

but gives a 404 error page.

Location of file:
/home/sass/public_html/cmsAdmin/lib/viewer_functions.php

Is that the info you needed?

Jono

By (Deleted User) - April 20, 2010

they are all at the root of the domain.

J

Re: [jonoc73] Simple SEO rewrite using htaccess

By Jason - April 20, 2010

Okay, that would be the problem.

Our original solution redirected to a folder called conditions :
www.mywebsite.co.uk/conditions/detail-1.html.

Since there isn't a conditions folder, try this:
<?php
$location = $_SERVER['QUERY_STRING'].".html";
header("Location:$location");
?>


Give that a try.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By (Deleted User) - April 21, 2010

I'm afraid that too gives a 404 error as it directs to:

www.mywebsite.co.uk/detail-1.html

Sorry about all this!

Jono

Re: [jonoc73] Simple SEO rewrite using htaccess

By Jason - April 21, 2010

If you find detail-1.html and open it, what is the url it gives? What is the url of conditions.php?

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Chris - April 28, 2010

Hi Jono,

Please let me know if I have this right:

1. You have a script called /conditions.php which works fine if you remove the header("Location:...") code which you recently tried adding.

2. You want this script to appear to serve requests that look like /conditions-123.html instead of /conditions.php?123

3. There aren't actually any /conditions-123.html files, you just want to make it appear like they exist.

If that's correct, you'll only need the rewrite rule, not the header("Location:...") code. Your rewrite code looks good, (I tried it myself here and it worked fine,) so if things still aren't working, you could try a simpler rewrite to make sure rewrites are working (e.g. rewrite foo.html to bar.html) or if you have access to httpd.conf [url http://www.latenightpc.com/blog/archives/2007/09/05/a-couple-ways-to-debug-mod_rewrite]you could try turning on rewrite logging[/url] so see if anything is going awry.

I'm afraid there isn't too much else we can do here on the forums, but our consulting team could probably get this figured out for you if all else fails. Please let me know if you're interested in that.

I hope this helps. Please let us know how it goes or if you have any questions.
All the best,
Chris

Simple SEO rewrite using htaccess

By (Deleted User) - May 5, 2010

Jason has done loads to help on this one and has come up with the correct results:

Add this to the htaccess file and it gets rid of the .php?

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteRule ^conditions/([^\.]+)$ conditions.php?id=$1 [NC,L]

Thanks Jason for all your help!

Jono