Search code examples
regexlinuxapachemod-rewriteserver

Apache mod_rewrite regexp


Can anyone tell me the Apache mod_rewrite code for this:

messages/reply/361568/T2kgdHVk%7CbyBiZW0gPyAgOik

My try that gives 404 error:

  RewriteCond "%{REQUEST_URI}"  messages\/reply\/(\d+)\/(.*)$
  RewriteRule  messages\/reply\/(\d+)\/(.*)$    /index.php?o=m&t=reply&mid=$1&det=$2 

Solution

  • You can just use:

    RewriteRule ^messages/(reply)/(\d+)/(.+)$ index.php?o=m&t=$1&mid=$2&det=$3 [L,QSA,NC]
    

    There is not need to use redundant RewriteCond "%{REQUEST_URI}" as we can match and capture REQUEST_URI segments from RewriteRule itself.