Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have to redirect many urls

the structure is this:




product18name.php (is merely an example)

i wish to do a regex, if a user type /anyword/product-18-name.aspx i wish that user will go to product18name.php

in short, i wish that the word in the middle of 2 first slashes, example: /category/ that maybe a real category or any word to go to right page

so a user that type: /helloworld/product-18-name.apsx goes to product18name.php or /sdjfkskfdns/product-18-name.apsx goes to product18name.php

Now my .htaccess is full of 301 redirects, like

Redirect 301 /electronic/peacemaker2_a5f89948-9f15-4606-9d5c-051d84a4c070.aspx

any help ? thanks

share|improve this question

A rewrite rule to rewrite any-directory/product-18-name.aspx to product18name.php may look like this

RewriteRule ^(.*)/product-18-name.apsx /product18name.php

share|improve this answer
Correct rule: RewriteRule ^(.*)/product-18-name.apsx [R=301,NC,L] works like a charm! For example: redirect correctly to – ienabellamy Sep 28 '12 at 15:43
Im happy you did it :) – Hex Sep 28 '12 at 17:26

Your Answer


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.