Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/174644-rewrite-rule-to-remove-file-extension/
Share on other sites

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?

 

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

 

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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.