1

How to make both links and images work in .htaccess
this is what i want

www.example.com/randomword --> /index/q1.php?encid=$1
www.example.com/anyname.jpg --> /index/img/q2.php?encid=$1

I tried this rewrite rule, but its not working

RewriteRule ^(.*)$ ./index/q1.php?encid=$1 [N,NC,QSA]
RewriteRule ^(.*\.(gif|jpg|png))$ ./index/img/q2.php?encid=$1 [L,NC,QSA]

When i used the links individually it works fine, but when i combine, its not working

1
  • i tried using sub directory for images, which also not working RewriteRule ^index/(.*\.(gif|jpg|png))$ ./index/img/q2.php?encid=$1 [L,NC,QSA]
    – Ragav
    Apr 28, 2020 at 14:37

1 Answer 1

1

I created two .htaccess files for each rewrite rule. One in main folder and another in sub directory and its working.

.htaccess

RewriteRule ^(.*)$ ./index/q1.php?encid=$1 [N,NC,QSA]

image/.htaccess

RewriteRule ^(.*\.(gif|jpg|png))$ ./q2.php?encid=$1 [L,NC,QSA]
1
  • 1
    OR, you could have just reversed the order of your original directives. But remove the N flag from the first rule. The first (more generic) rule was catching everything. Also, remove the ./ prefix from the substitution.
    – MrWhite
    Apr 28, 2020 at 15:39

You must log in to answer this question.

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