I am using this code in .htaccess but the last line not giving any response:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ user_pro.php?id=$1 [QSA,L]
RewriteRule ^(.*)$/images image.php?id=$1 [QSA,L] #this line not giving any response
  • $ in the last pattern will match a $ and not EOL
    – AgA
    Jan 31, 2014 at 7:03
  • yes u r right @Aga . Can u tell what if user add a slash (/) after images like this http://www.funnenjoy.com/foo/images/ Jan 31, 2014 at 11:04

2 Answers 2


the $ anchor signals the end of the subject (as ^ signals the start), thus your expr is incorrect.

What you're lookng for is more likely something like

# to rewrite images/foo to image.php?id=foo
RewriteRule ^images/(.*)$ image.php?id=$1 [QSA,L]

# to rewrite foo/images to image.php?id=foo
RewriteRule ^(.*)/images$ image.php?id=$1 [QSA,L]

For more info have a look at mod_rewrite intro and the mod_rewrite documentation

  • what if user types foo/images/ than foo/images is working Jan 31, 2014 at 10:55
  • 1
    you mean you want it to work whether there is a trailing slash or not? In that case you can use the ?. e.g. RewriteRule ^(.*)/images/?$ image.php?id=$1 would kick both foo/images and foo/images/ to image.php?id=foo
    – vollie
    Jan 31, 2014 at 16:47
  • thanks for reply and and good answer in above comment can this also work RewriteRule ^(.*)/?$ user_pro.php?id=$1 [QSA,L] for /foo and for /foo/ Jan 31, 2014 at 19:37
  • Well, it would match, but it would give you foo and foo/ respecively as the IDs. Patterns like these are "greedy" meaning in this case the .* will match anything; the / included. If you want it to match anything but a /, yet accept an optional trailing slash use RewriteRule ^([^/]*)/?$ user_pro.php?id=$1 [QSA,L]
    – vollie
    Feb 1, 2014 at 8:16

First, make sure mod_rewrite is on: *https://httpd.apache.org/docs/current/mod/mod_rewrite.html*

  1. If you're on a linux machine like Centos, you can check by running httpd -l to list compiled (installed) modules.

  2. https://stackoverflow.com/questions/7337724/how-to-check-whether-mod-rewrite-is-enable-on-server

Lastly, are you including RewriteEngine on at the beginning of your code?

Try :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ user_pro.php?id=$1 [QSA,L]
RewriteRule ^(.*)$/images image.php?id=$1 [QSA,L]

I'm not really familiar with the syntax, so I can't tell you whether ^(.*)$/images image.php?id=$1 [QSA,L] is proper or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.