URL Mod Rewrite Question...

7 replies
Hi,

I am having problems getting a mod rewrite on my .htaccess file to work.

I have added the following code to the file........

Options +FollowSymLinks
RewriteEngine on

RewriteRule product-product-(.*)\.php product.php?product=$1

The original url is something like....

http://www.mysite.co.uk/product.php?...%20highlighter

and I want the url to rewrite to..........

Example: http://www.mysite.co.uk/product-prod...ighlighter.php

I have used a website tool to create this rewrite. Is there a reason this wouldn't work?

Ideally, i'd like to rewrite the over url to something like.........

http://www.mysite.com/product/Malmo-...th-highlighter

I also have another url to rewrite to something like.......

http://www.mysite.com/category/Highlighter-Pens

Could anyone point me in the right direction of how I could do this?

Any help would be greatly appreciated!

Many thanks

Andy
#mod #question #rewrite #url
  • Profile picture of the author ehicks727
    Originally Posted by AndyBlackSEO View Post

    RewriteRule product-product-(.*).php product.php?product=$1
    First of all, I don't know why you have product in the matching URL twice... that's kind of awkward. Anyway, try something like this... I don't know if this will work or not btw, I'm not a mod_rewrite wizard... I just search and experiment until I find my answers.

    RewriteRule ^product-product-(.*)$ /product.php?product=$1


    As far as...
    Originally Posted by AndyBlackSEO View Post

    Ideally, i'd like to rewrite the over url to something like.........

    http://www.mysite.com/product/Malmo-...th-highlighter
    You have to do that in your code. In pseudo-code, it would look like this...

    1. rewrite the url
    2. grab what ever is after "product/"
    3. check the database for a match
    4. if it doesn't match, display 404
    5. if it does match, display page
    {{ DiscussionBoard.errors[674603].message }}
  • Profile picture of the author AndyBlackSEO
    Thanks ehics,

    Unfortunately that doesn't do anything. Whatever I seem to add just has no effect on anything.

    I contact my host last week and they said all I had to do was add the correct code to the .htaccess file which I have done. Nothing else needs to be 'turned on' according to them.

    I'm a bit stuck. If it changed something then at least i'd know I was on the right track but whatever I add to the .htaccess file, it doesn't make the blindest bit of difference.

    Andy
    Signature
    [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
    ... Instant backlinks that can get you results within 24-72hrs.
    {{ DiscussionBoard.errors[674786].message }}
    • Profile picture of the author Philarmon
      Just took a quick look on how my rewrites look like (i'm not a htaccess guru as well )

      Looks a bit different - maybe you want to try it out:

      RewriteRule ^product-product-([^-]*).php$ /product.php?product=$1 [L]

      Note that there is no "\" before the .php

      Not sure but it might be the spaces in the product name that are causing problems ? I never have any spaces in an URL.

      Another option would be to track the products with an id and add the product name just for the SEO purposes. Let's say the product id in your database is 556. Within your product name, replace all spaces with "-" before you add it to the URL so the URL looks like this:

      http://www.mysite.com/product/556-Ma...th-highlighter

      Then this rewrite would definately do the job:

      RewriteRule ^product-product/([0-9]*)-([^-]*)$ /product.php?id=$1 [L]

      Then just get the product data by id rather than by product name within your product.php script (should be faster to get a int rather than varchar from the database as well)

      Hope that helps
      {{ DiscussionBoard.errors[676385].message }}
  • Profile picture of the author AndyBlackSEO
    Hi thanks! I'll try that out now. I would normally use an id, but because I wanted to use the product name or category name within the url I setup the system this way. As I programmed my system to not add duplicate product names I thought this would be ideal for SEO.

    I'll give your url syntax a go and see what happens.

    Thanks!

    Andy
    Signature
    [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
    ... Instant backlinks that can get you results within 24-72hrs.
    {{ DiscussionBoard.errors[677460].message }}
  • Profile picture of the author AndyBlackSEO
    Just tried that and there is no difference to the displayed url at all. I'll spend the rest of the day trying to work this out otherwise i'll just get the site indexed with dynamic urls... which isn't what I wanted to do.

    If you have any other ideas why it is not noticing the rewrite i'd love to hear them.

    Thanks

    Andy
    Signature
    [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
    ... Instant backlinks that can get you results within 24-72hrs.
    {{ DiscussionBoard.errors[677469].message }}
  • Profile picture of the author AndyBlackSEO
    My host said that I can't just do a mod rewrite using the .htaccess. He said with it using a mySQL databse I have to set the rule in the mySQL queries?!

    Does anybody understand this or steer me in the right direction. I'm stuck.

    Thanks

    Andy
    Signature
    [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
    ... Instant backlinks that can get you results within 24-72hrs.
    {{ DiscussionBoard.errors[678021].message }}
  • Profile picture of the author AndyBlackSEO
    Thanks Guys, but i've managed to sort everything now :-)
    Signature
    [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
    ... Instant backlinks that can get you results within 24-72hrs.
    {{ DiscussionBoard.errors[681290].message }}

Trending Topics