Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question

migrated from stackoverflow.com Oct 10 '12 at 12:12

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

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
share|improve this answer
    
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 '12 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? –  Ansgar Wiechers Oct 10 '12 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 '12 at 11:04
    
The documentation for the RewriteBase directive has an example. –  Ansgar Wiechers Oct 11 '12 at 11:42
add comment

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.