1

I am trying to redirect a URL that looks like this: http://getdotastats.com/sig/28755155.png

To one that looks like this: http://getdotastats.com/sig/?aid=28755155

The first URL being the imaginary one that does not exist.

The regex I cam up with is below. Can you see how to improve it. I lack the necessary know how in forming the regex, so I just made it match groups, and ignore the ones I don't need.

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)sig/(.*)\.(.*)$ index.php?aid=$2 [NC,L]

Can I just throw the above in a .htaccess in the specific directory (/sigs), or are the additional directives required in the main vhost file?

Thanks for helping!

EDIT: Thanks futuretelematics. Using the .htaccess below:

RewriteEngine On
RewriteBase /
RewriteRule testpage\.html http://www.google.com [R]
RewriteRule ^/sig/([0-9]+\.(?:gif|png|jpg))$ index.php?aid=$1 [NC,L]

The testpage redirect to google, but the image redirect throws the following error.

The requested URL /sig/28755155.png was not found on this server.

We must be close. _

Vhost looks like:

    DocumentRoot /home/www-dota2
    <Directory /home/www-dota2/>
            Options Indexes MultiViews +SymLinksIfOwnerMatch
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
user2470736
  • 25
  • 1
  • 6

1 Answers1

0

First of all, I'd recommend you to write more specific regex: To match /sig/28755155.png, I'd do:

RewriteRule ^/sig/([0-9]+\.(?:gif|png|jpg))$ index.php?aid=$1 [NC,L]

Bear in mind that your regex ^(.)sig/(.).(.*)$ could match paths like /somesig/foo/bar/123.png

Aswering to your question:

  • YES, you can put this rules in a htaccess file of your sig folder
  • YES the rules in htaccess in sig folder are computed for any subfolder (ej: /sig/foo/bar)

Hope this helps

futuretelematics
  • 1,453
  • 11
  • 23
  • Sorry for the delay. Thanks for the regex. I just need to sort out why it isn't working. It tells me that the file does not exist, which leads me to believe mod_rewrite is incorrectly configured. – user2470736 Jun 13 '13 at 12:17
  • Does not appear to be a config issue. *_* .htaccess here: http://pastebin.com/AkauwEM2 The google redirect works, but the image one does not. It tells me "The requested URL /sig/28755155.png was not found on this server." – user2470736 Jun 13 '13 at 12:23
  • I think the regex should be: RewriteRule ^sig/([0-9]+)\.(?:gif|png|jpg)$ /sig/index.php?aid=$1 [NC,L] ... unfortunately that does not work either. – user2470736 Jun 13 '13 at 13:48
  • Ended up writing a different regex to get it working. Thanks for the help though! http://pastebin.com/kbvqMUXk – user2470736 Jun 13 '13 at 15:17