rachelk Posted September 17, 2009 Share Posted September 17, 2009 I'm wondering if there's a way to be able to access the urls http://site.com/gallery/image-name.gif (which leads to an actual page through a gallery script, not an image) through the url http://site.com/gallery/image-name With each extension being either .jpg or .gif.. is this possible? Thanks in advance for any help. Quote Link to comment https://forums.phpfreaks.com/topic/174644-rewrite-rule-to-remove-file-extension/ Share on other sites More sharing options...
MadTechie Posted September 17, 2009 Share Posted September 17, 2009 something like this RewriteEngine On RewriteRule ^gallery/([^\.]*).\w{1,3} gallery/$1 Quote Link to comment https://forums.phpfreaks.com/topic/174644-rewrite-rule-to-remove-file-extension/#findComment-920411 Share on other sites More sharing options...
rachelk Posted September 17, 2009 Author Share Posted September 17, 2009 Thanks for your help. I accidentally forgot to add a folder in the url in my first post (it's http://site.com/gallery/gallery-name/image-name.gif) so I think that might be preventing the code from working, and I think there are other things in my .htaccess for the gallery folder that might affect it like: RewriteRule ^([^/\.]+)/?$ index.php?cat=$1 [L] which makes site.com/gallery/paris lead to the paris category page RewriteRule ^([^/]*)/([^/]*)$ preview.php?cat=$1&img=$2 [L] which makes site.com/gallery/paris/image-name.gif lead to the image page So I think if I add another rule it'd think I'm looking for another category and lead me to the category page as not found.. so because of these other rules would it not be possible for me to make site.com/gallery/paris/image-name.gif accessable as site.com/gallery/paris/image-name? Quote Link to comment https://forums.phpfreaks.com/topic/174644-rewrite-rule-to-remove-file-extension/#findComment-920430 Share on other sites More sharing options...
MadTechie Posted September 18, 2009 Share Posted September 18, 2009 just add the ? to the end RewriteRule ^gallery/([^\.]*).\w{1,3} gallery/$1? RewriteRule ^([^/]*)/([^/]*)$ preview.php?cat=$1&img=$2 [L] which makes site.com/gallery/paris/image-name.gif lead to the image page if I'm reading that correctly, it would make site.com/paris/image-name.gif (no gallery) goto preview.php?cat=paris&img=image-name.gif Quote Link to comment https://forums.phpfreaks.com/topic/174644-rewrite-rule-to-remove-file-extension/#findComment-920434 Share on other sites More sharing options...
rachelk Posted September 18, 2009 Author Share Posted September 18, 2009 if I'm reading that correctly, it would make site.com/paris/image-name.gif (no gallery) goto preview.php?cat=paris&img=image-name.gif This .htaccess is located in site.com/gallery so it's in that folder and not in the root of my site.. sorry I didn't add that earlier! When using your code I remove the gallery folder and put: RewriteRule ^([^\.]*).\w{1,3} $1? since it's in that folder.. is that the wrong way to do it? When I did add that line I got a 500 internal server error when trying to access anything in the gallery folder including the index page.. is possible my server is not compatible with using that method? I tried it several times and it loaded fine when I delete that line and kept coming up with that error when I add it. Quote Link to comment https://forums.phpfreaks.com/topic/174644-rewrite-rule-to-remove-file-extension/#findComment-920444 Share on other sites More sharing options...
rachelk Posted September 19, 2009 Author Share Posted September 19, 2009 I've been googling for hours but can't seem to get this working! Quote Link to comment https://forums.phpfreaks.com/topic/174644-rewrite-rule-to-remove-file-extension/#findComment-920999 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.