best way to change website structure without losing serp

Joined
12 Feb 2006
Posts
17,675
Location
Surrey
currently one of my sites uses the following structure co.uk/pictures.php?p=photography&x=album2 which really needs to change as it looks very ugly on search results and links in general.

I think a mod rewrite would be best so that i can get something like .co.uk/pictures (i like not having the .php) but i don't want to lose any serp so would appreciate any advice as to how i should go about doing this.

if mod_rewrite is the way to go then how do i change links on my site? will i need to go through and make links now point to /pictures/photography/album1 rather then /pictures.php etc? also the same for links to the old pages? i guess htaccess to redirect to new pages?

thanks
 
serp?!

also, yes, mod re-write using standard regex. Google for "mod_rewrite" and you'll get a thousand tutorials and examples.
 
I'd not heard of "serp" before. :)

mod_rewrite won't hurt your rankings, in fact Google prefer readable uri's to query string variables. :)
 
If anything your variable urls are hindering your ranking at the moment. Get some nice urls and you may see a ranking improvement.
 
ok i'm still a little confused with how mod_rewrite works. do i continue to internally link to pages as normal e.g. ?p=services&s=webdesign, and then mod_rewrite will automatically change this for me to something nice i specify such as .co.uk/serivces/web-design and it'll also automatically redirect the user that clicks on an old link to the ugly url to the nicer new one?

if not can someone explain. i'm doing a new site and i'm not sure if i should set it up without mod_rewrite now so linking to pages such as about/faq.php, and then let mod_rewrite change this to something nicer, or should i link now to about/frequently-asked-questions ?

i feel like if mod_rewrite doesn't auto change my internal links to the nicer urls then whats the point of it as i could change the urls and then the structure without mod_rewrite to the same surely?
 
Last edited:
It seems to me you're looking to use different URLs for static files is that correct?

So for instance you have a file at http://www.yourdomain.com/faq.php and you'd like that to be accessible at http://www.yourdomain.com/frequently-asked-questions/ ?

Two ways of doing that, first change the faq.php to index.php or default.php depending on your directory index setting:

Code:
# Look for index.php first then default.php
DirectoryIndex index.php default.php

and then stick it in a folder called frequently-asked-questions at your root. Kind of messy so using mod_rewrite you could use:

Code:
# frequently-asked-questions to /frequently-asked-questions/
# frequently-asked-questions/ to /faq.php
RewriteRule ^frequently-asked-questions$ /frequently-asked-questions/ [R=301,L]
RewriteRule ^frequently-asked-questions/?$ /faq.php[L]

So you can link to http://www.yourdomain.com/frequently-asked-questions/ in your navigation and it'll show the user http://www.yourdomain.com/faq.php

I use mod_rewrite a lot in sites to make the URLs content relevant and lose the horrible querystring structure. So using the following:

Code:
#products/productName/productId to /products/productName/productId/
#products/productName/productId/ to /products.php?productId=productId
RewriteRule ^products/([^/]+)/([0-9]+)$ /products/$1/$2/ [R=301,L]
RewriteRule ^products/([^/]+)/([0-9]+)/?$ /products.php?productId=$2 [L]

I can link to http://www.mydomain.com/products/a-sought-after-item/1/ instead of http://www.mydomain.com/products.php?productId=1

Redirecting from your .faq.php to your new /frequently-asked-questions/ might get stuck in a loop if you try it with mod_rewrite, it can be tricky at times, but give it a try and if there's a problem it'll error straight away. You could perhaps call a header with a 301 in the php page if the address is the old one and that'll forward anyone to the new address with the same content.

Sorry I can’t help more on that one, only ever redirected from a different structure so the looping wouldn’t be a problem. The key thing to remember is to make sure users and Google don’t get a 404, and that your content can’t be found at two different addresses as that will likely penalise you for having duplicate content.
 
thanks for the reply.

so for the second example you gave which was to change the ugly query string into something nice, is this not internally done then with my links? i can leave them as they currently are and then just enabled the mod_rewrite and it's all done assuming i get no errors?
 
Depends really, you should really rewrite your links on your pages to the new addresses. I'm not sure how google would react to it. If you can be bothered I would as then you can have the keywords in your anchor texts as well.

I personally would use another name for the php file to avoid confusion.

So something along the lines of:

Code:
#pictures.php?p=photography&x=album2 to /pictures/photography/album2/
RewriteRule ^pictures.php?p=([A-Za-z0-9]+)&x=([A-Za-z0-9]+)$ /pictures/$1/$2/ [R=301,L]

(someone might be able to help you clear up that regex, not my strong point) and then combine it with:

Code:
#pictures/p/x to /pictures/p/x/
#pictures/p/x/ to /picturesNu.php?p=p&x=x
RewriteRule ^pictures/([^/]+)/([^/]+)$ /pictures/$1/$2/ [R=301,L]
RewriteRule ^pictures/([^/]+)/([^/]+)/?$ /picturesNu.php?p=$1&x=$2 [L]

Not tested it but hopefully it should work ok
 
Code:
RewriteEngine on
RewriteRule ^pictures/([a-z]+)/([a-z0-9]+)$ pictures.php?p=$1&x=$2
This should do what you wanted in your OP. Depending on how the rest of your site is structured you may have to use different rewrite rules for other pages.
 
mod_rewrite is really useful and I love it, examples above are a good start, I've never written a mod_rewrite rule from scratch, I'm always barbarising other people's or old code :p

Can you show us your website, would be able to give the best advice then, but you will need to write rules to make your structure and redirect old queries correctly to the new pages.
 
I definitely wouldn't use mod_rewrite if you don't need to.

But looking at an example there it may be best to actually restructure it as it looks like you would be looking at URLs like this:

http://www.greencleansolution.co.uk/services/office

in order to pass the parameters to the script you already have. If I were you I would restructure the links so they all require one parameter as there doesn't seem to be a need for two and then 301 redirect all your best keyword magnet pages to the new equivalent pages.

If that makes sense :P mod_rewrite is easiest and most effective when you have designed your site to use them originally.
 
Back
Top Bottom