Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

If I have URL's like:-

domain.com/category/widgets/filter/blue
domain.com/category/widgets/filter/red

And it is pretty difficult to reconstruct them to something like:-

domain.com/category/blue-widgets
domain.com/category/red-widgets

Is there any way at all that I can use URL rewrites or anything else with .htaccess or on the server to display the URL's as the domain.com/category/blue-widgets on the domain.com/category/widgets/filter/blue page?

I've looked into masking URL's but got nowhere and this has been something bugging me for almost 6 months now. Is there any way to achieve what I want to do?

FYI: This is a Magento website and the above process, I am wanting to implement for potentially hundreds of URL's.

Edit

To respond to @kkugelmann's answer:-

I couldn't get your proposed RewriteRule to make a difference at all in the .htaccess file so I started testing a few things in this .htaccess tester:-

The proposed RewriteRule didn't work in this tester:-

enter image description here

However, the following did:-

enter image description here

But adding any of these RewriteRule's into the website's .htaccess file did not rewrite the URL at all...

Edit2

By the way, if I add [R=301,L] to the end of the URL rewrite rule, it does actually then rewrite the rule, but of course 301 redirects it as well which is unwanted behaviour.

Edit3

I found another question with the same issue... And an accepted answer that solved the problem which seemed to be something to do with using mod_proxy and the [P] tag on the rule (if I try this, the page 404's).

share|improve this question

1 Answer 1

You'll need mod_rewrite activated and your rewrite command should look like this:

RewriteEngine on 
RewriteRule ^category/([a-zA-Z]*)-([a-zA-Z]*)$ category/$2/filter/$1^

[Update]

RewriteEngine on 
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/filter/([a-zA-Z]+)$ $1/$3-$2
share|improve this answer
    
Thanks for your answer, I've updated my question to respond to your answer... I'm wondering if you could spare 10 minutes of your time on chat to look at this further with me please? The RewriteRule in the .htaccess just doesn't want to work for some reason but I suspect you're very close with this. –  zigojacko May 1 at 11:03
    
Have you enabled mod_rewrite? –  kkugelmann May 1 at 12:30
    
The Screenshots look like you want the conversion to be vice-versa... I'll rewrite the script for you and also add a third variable for the category –  kkugelmann May 1 at 12:32
    
Thanks but same problem as before. The RewriteRule's are not taking affect in the .htaccess. Others are, but these ones aren't. Did you read all the above edits in the question? I'd be happy to paste the entire .htaccess contents if you can spare 10 mins of your time. –  zigojacko May 1 at 12:56
    
Could you paste the wohle .htaccess file to pastebin? I can take a look. –  kkugelmann May 1 at 14:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.