0

My website is built up like the following

www.domain.com/products/catname/myproduct.php

www.domain.com/products/myproduct.php

Some files are in deeper directories. I am wanting to redirect www.domain.com/products/catname/ (for example) to a certain page. My directories do not include index files.

How do I do this using htaccess?

I have tried

Options +FollowSymLinks
RewriteEngine On
RedirectMatch permanent ^/products http://domain.co.uk/
RedirectMatch permanent ^/products/productname http://domain.co.uk/

But this redirect any file in the /products directory (domain.co.uk/products/prod1.php for example will redirect to domain.co.uk)

  • Options +FollowSymLinks RewriteEngine On RedirectMatch permanent ^/products domain.co.uk RedirectMatch permanent ^/products/productname domain.co.uk – LCDesign Cambridge Oct 2 '12 at 18:37
  • This redirect the /products/product.php to the destination which it shouldnt. Only is someone browses to the directory root – LCDesign Cambridge Oct 2 '12 at 18:38
  • Update your question with that, that way more people can help you. – Nelson Oct 2 '12 at 18:38
  • I have updated it :-) – LCDesign Cambridge Oct 2 '12 at 18:40
0

Using mod_alias:

Options +FollowSymLinks
RewriteEngine On
RedirectMatch permanent ^/products/?(productname)?$ http://domain.co.uk/

Using mod_rewrite:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/?products/?(productname)?$ http://domain.co.uk/ [L,R=301]
  • Works a treat...just one thing.. So I have it redirected to tempdomain.com/page.php I am building the site on a demo server. So I will have to change each redirect link. Unless there is a way to pull the host address?? – LCDesign Cambridge Oct 2 '12 at 19:34
  • @LCDesignCambridge not sure what you mean by having to change each redirect link. – Jon Lin Oct 2 '12 at 20:30
  • @LCDesignCambridge Oh wait, do you mean you are redirecting to the same host that you are requesting /products/ from? If so, then simply remove the http://domain.co.uk part, and it will redirect to the same host. – Jon Lin Oct 2 '12 at 20:31
  • great ok. If I need to go back a directory or two do I simply use ../ ? – LCDesign Cambridge Oct 2 '12 at 20:50
  • @LCDesignCambridge ../ isn't guaranteed to work. If you're going to need to redirect to a parent directory, try: http://%{HTTP_HOST}/ – Jon Lin Oct 2 '12 at 21:00
0

Try this:

Options +FollowSymLinks
RewriteEngine On
RedirectMatch permanent ^/products/[^/]+/ http://domain.co.uk/somepage.htm
RedirectMatch permanent ^/products http://domain.co.uk/

substitute 'somepage.htm' above for the actual page you want to redirect to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy