godius Posted September 26, 2009 Share Posted September 26, 2009 Hi guys, im trying to make a .htaccess file with mod_rewrite. My goal is to forward all 4 character filenames that are .jpg, to /pic.php?i=filenamehere. RewriteEngine On RewriteRule ^(.*)\.jpg$ /pic.php?i=$1 That works, but it forwards ALL jpgs on my server, but it should only fake the links that are straight on my domain root. http://domain.com/ABCD.jpg - this should be linked to http://domain.com/pic.php?i=ABCD.jpg ABCD.jpg = in the root directory, and is 4 characters. All other .jpgs should be ignored by this rewrite. Can anyone please help me get the right rewriterule? Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/175638-mod_rewrite-help-needed/ Share on other sites More sharing options...
corbin Posted September 26, 2009 Share Posted September 26, 2009 An easy solution would be to forward jpgs that don't exist to the other page: RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)\.jpg$ pic.php?i=$1 Or, to just match 4 characters: RewriteRule ^(.{4})\.jpg$ pic.php?i=$1 Quote Link to comment https://forums.phpfreaks.com/topic/175638-mod_rewrite-help-needed/#findComment-925542 Share on other sites More sharing options...
godius Posted September 27, 2009 Author Share Posted September 27, 2009 Corbin you da man!! works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/175638-mod_rewrite-help-needed/#findComment-925886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.