Short URLs


#1

Hi there,

I am quite new to Web creation so would appreciate any advice.

I have a site on Dreamhost that was made from a PHP website generator. I need to shorten the Static URLS on
this site.

Example: I want the URL:

http://www.bargainhealth.co.uk/vitamin/Joints/Inflamol_60_Capsules.html

to Shorten to

http://www.bargainhealth.co.uk/Inflamol_60_Capsules.html

Can I use a Mod reWrite to miss out the two middle
categories in the longer URL to make the short URL I want?

Thanks in advance for any advice.

Mark


#2

You can read all this, or simply skip to the very last paragraph, which is my educated summary :slight_smile:

Not really with mod rewrite as it wouldn’t know which product line you want it forwarding to… this is assuming you have more than one product type, such as joints, muscles, etc all having their own paths.

Joomla has a component called com_sh404SEF, which rewrites urls for you and stores them in a database based on the title of the page. You could have a look at this and write your own database driven version, although it might be overkill.

The problem lies in that for mod rewrite, apache needs to know where the page needs to forward to, so you can’t write a generic rule if you’re using multiple folders/paths. - Unless you add each rule by hand for each product, assuming the same product doesn’t apply to multiple products - such as ibuprofen working for multiple things.

If you do it manually, it may be hard to maintain, etc etc.

Possibly the most important point though… the urls you already have are GREAT for search engine optimisation… much more so than your desired rewritten ones. I’d seriously consider sticking with what you’ve got - much less hassle, and much better seo performance.

Cheers,
Karl

web design, development & seo by DigitalVibe


#3

Thanks for your reply,

If I cant shorten them to the extent that I wanted initially then is it possible to at least loose the useless ‘Vitamin’ level in the middle. So that for example the URL

http://www.bargainhealth.co.uk/vitamin/Joints/Inflamol_60_Capsules.html

Would shorten to

http://www.bargainhealth.co.uk/Joints/Inflamol_60_Capsules.html

The current Htaccess rewrite looks like this:

RewriteEngine on RewriteRule ^vitamin/([A-Za-z0-9_-]+)/?$ category.php?category=$1&page=1 [L] RewriteRule ^vitamin/([A-Za-z0-9_-]+)/index.html$ category.php?category=$1&page=1 [L] RewriteRule ^vitamin/([A-Za-z0-9_-]+)/([0-9]+)/?$ category.php?category=$1&page=$2 [L] RewriteRule ^vitamin/([A-Za-z0-9_-]+)/index([0-9]+).html$ category.php?category=$1&page=$2 [L] RewriteRule ^vitamin/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+).html$ product.php?category=$1&product=$2 [L] RewriteRule ^sitemap/?$ sitemap.php?page=1 [L] RewriteRule ^sitemap/index.html/?$ sitemap.php?page=1 [L] RewriteRule ^sitemap/([0-9]+)/?$ sitemap.php?page=$1 [L] RewriteRule ^sitemap/index([0-9]+).html$ sitemap.php?page=$1 [L]

Thanks in advance,

Mark


#4

Hi Mark,

Looking at the htaccess file, to get it to work as-is without the “vitamin/” part, it’ll end up rewriting everything as though it’s a product. It looks like the “vitamin/” part is a bit of a dirty hack to make sure it only treats the vitamin category as a part of the “shop”.

What you could do is replicate this functionality but replace “vitamin/” with “Joints/”.

Downside being you’ll need to do this for all ailments.

eg:

RewriteRule ^Joints/?$ category.php?category=Joints&page=1 [L] RewriteRule ^Joints/index.html$ category.php?category=Joints&page=1 [L] RewriteRule ^Joints/([0-9]+)/?$ category.php?category=Joints&page=$2 [L] RewriteRule ^Joints/index([0-9]+).html$ category.php?category=Joints&page=$2 [L] RewriteRule ^Joints/([A-Za-z0-9_-]+).html$ product.php?category=Joints&product=$2 [L] This will prevent it from trying to rewrite other urls as products, protecting the integrity of the rest of your website.

Downside being that you’ll need to replicate the example above for every category on your site… eg Joints, Muscles, Bones, etc.

Let us know how you get on with it. I’m no mod_rewrite guru, so my code might not work “straight out of the box”, but it should give you an idea of what to do if not!

Cheers,
Karl

web design, development & seo by DigitalVibe