1

I'm trying to create a 301 redirect rule for a website I'm setting up. The old link structure is as follows:

http://www.domainname.com/projecttype/subtype/post-name

The new structure is:

http://www.domainname.com/projectname/projecttype/subtype/post-name

So basically I need to add "projectname" between domainname and projecttype. But only if there is a subfolder after projecttype. As domainname.com/projecttype/ <-- need no redirect..only redirect if a subdirectory after this exist in the url.

I've never written any regexp or redirect rules before..tried searching for something that matched my need without any luck so far :(

1 Answer 1

1

Try:

RedirectMatch ^/projecttype/(.+)$ /projectname/projecttype/$1

That's assuming that both project type and name are static.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your quick response. Will give it a go. Just a short follow up question: wouldn't the domain be needed before "/projecttype/" to avoid a loop ? I mean since /projecttype/ would still exist in the url after the redirect..only now with /projectname/ before it? Or does the "^" before /projecttype/ handle this in some way? :)
@user3708279 it won't loop because the regex matches URI's that start with /projecttype/ (that's what the ^ does), so when you redirect to /projectname/projecttype, that won't match the regex.
Worked perfectly. Thanks alot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.