0

Say I have content in www.domain.com/products/

In the products folder, I have several html files all starting with "big-". For example:

big-product01.html
big-product02.html

How can I rewrite my URLs so that I could access these by typing:

www.domain.com/products/big/product01
www.domain.com/products/big/product02
...

Thanks in advance for any help on that!

1 Answer 1

2

Using mod_rewrite (should not change the URL in the browser):

<Directory /var/www>
  RewriteEngine on
  RewriteRule ^products/big/(product[0-9][0-9]*)$ /products/big-$1.html [L]
</Directory>

If the <Directory> block has a relative path, you need a RewriteBase directive too.

Using mod_alias (will change the URL in the browser):

RedirectMatch permanent /products/big/(product[0-9][0-9]*)$ /products/big-$1.html
4
  • Thank you. The solution using mod_alias works. Not the one using mod_rewrite. Also I wish the URL would not change in the browser address bar after the rewriting. Have tried playing with your mod_rewrite solution without success until now.
    – MrUpsidown
    Oct 10, 2012 at 19:55
  • Did you put the rewrite directives in a <directory> block (see my updated answer)? What does your error.log say about your failed attempts? Oct 10, 2012 at 21:53
  • Thank you. Will try that. Not sure I understand the 'relative path' part. The root path seems to be /html/products. Checking right now with my provider to see how I can access that log file. Will report back later.
    – MrUpsidown
    Oct 11, 2012 at 11:04
  • The documentation for the RewriteBase directive has an example. Oct 11, 2012 at 11:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .