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 17, 2010 - edited: May 5, 2010

Hello,

I'm sure someone will know how to do this but I am going round and round in circles trying to work it out. I have an htaccess file at the root of my domain and would like to rewrite the following:

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

TO
http://www.mywebsite.co.uk/conditions/detailpage-1.html


Any ideas from anyone would be great!

Thanks Jono

Re: [jonoc73] Simple SEO rewrite using htaccess

By darrylo - April 18, 2010

Paste this into the .htaccess file

Redirect permanent /http://www.mywebsite.co.uk/conditions.php?detailpage-1 http://www.mywebsite.co.uk/conditions.php?detailpage-1.html
Darryl
http://darrylo.com

Re: [darrylo] Simple SEO rewrite using htaccess

By (Deleted User) - April 18, 2010

Thanks darrylo for the info but I should have been a little more clear! I meant it to be dynamic.

To dynamically change whatever is after the ? and take out the .php? and replace it with /

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

as well as:

FROM
http://www.mywebsite.co.uk/conditions.php?detailarticle-5
TO
http://www.mywebsite.co.uk/conditions/detailarticle-5.html

for example - thanks J

Re: [darrylo] Simple SEO rewrite using htaccess

By (Deleted User) - April 18, 2010

Thanks once again for your help.

However when I put say http://www.mywebsite.co.uk/conditions.php?detailpage-1 in it comes back as just http://www.mywebsite.co.uk/conditions.html

Any ideas?

Thanks Jono

Re: [jonoc73] Simple SEO rewrite using htaccess

By darrylo - April 18, 2010

http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

First example looks like what you are looking for.
Rewriting product.php?id=12 to product-12.html
Darryl
http://darrylo.com

Re: [jonoc73] Simple SEO rewrite using htaccess

By Jason - April 19, 2010

Hi, you could put this a the top of your php file:
<?php
$location = "/conditions/".$_SERVER['QUERY_STRING'].".html";
header("Location:$location");
?>


What this will do is get the variable from the query string (detailpage-1 for example) and put a .html at the end of it. It will then redirect the page to your conditions folder and look for that page (conditions/detalpage-1.html).

This does have to be at the very top of the page though, or you may get an error.
Give it a try and let me know how it works.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Simple SEO rewrite using htaccess

By (Deleted User) - April 20, 2010

Thanks for trying to help but I just get 404 errors when I add this to the top.

The other examples of code - I can't get them to work either. It's so frustrating as I know it can be done! Thanks for everyone's help so far though...

Re: [jonoc73] Simple SEO rewrite using htaccess

By (Deleted User) - April 20, 2010

I do have some other bits n bobs in the htaccess - could they be effecting anything?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.co.uk [NC]
RewriteRule ^(.*)$ http://www.mywebsite.co.uk/$1 [L,R=301]
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
</ifmodule>
FileETag none
<IfModule mod_deflate.c>
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
RewriteEngine on
RewriteRule ^conditions-([0-9]+)\.html$ conditions.php?id=$1

Re: [jonoc73] Simple SEO rewrite using htaccess

By Jason - April 20, 2010

Hi,

The .htaccess file looks ok.

What is the exact URL that is outputted when you get the 404 error? What is the exact path of both the file where we are using the header() function and the path of the file we're trying to get to?

Let me know and we'll try to get it figured out.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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