Mod rewrite

Hello,

Can you help in make all urls that have /solutions/ get directed to /solutions-and-services/ regarding when is before and after it. For example


www.mysite.com/eng/solutions/sol1

get directed to


www.mysite.com/eng/solutions-and-services/sol1

In addition if the url is missing the person get directed to the index.php

Thank you

How do you mean, “when a URL is missing”? When there is no directory by the name you mean? Also, why don’t you just want to show your visitors a 404 so they know their request can’t be resolved?

Hello,

You are right, I will stick with 404 page.

How about my first request. Do you have any suggestion for me?

TIA

I would try something like


RewriteEngine On
Options +SymLinks

# If the URL does not contain "solutions-and-services" ...
RewriteCond %{REQUEST_URI} !solutions-and-services
# ... replace "solutions" with "solutions-and-services"
RewriteRule (.*)solutions(.*) $1solutions-and-services$2 [L,R=301]

May not be the best solution but it should work.
Note that it will not replace multiple instances within one URL. Just the first one it finds. So /solutions/solutions will be rewritten to /solutions-and-services/solutions

Also note that I’ve put a 301 redirect in that code. While testing, change 301 to 302 so the browser doesn’t cache it. Once you’ve established the rule works, change 302 back to 301.