Welcome Guest, Not a member yet? Register   Sign In
htaccess: swfuploads vs trailing slashes
#1

[eluser]Leon Stafford[/eluser]
Hi,

I need some help with my .htaccess file.

I'm adding trailing slashes to all but files and FreakAuthLight via my .htaccess rewrite rules.

That's all peachy, but then SwfUpload breaks for my file uploads.

FireBug lists the filename without the extension, then it looks like instead of getting the image, it gets the filename variable plus a trailing slash.

Code:
GET 7f000001-8f09-cbf6
http://localhost/uploads/7f000001-8f09-cbf6
    
301 Moved Permanently
    
GET 7f000001-8f09-cbf6
http://localhost/uploads/7f000001-8f09-cbf6/
    
404 Not Found

I tried setting the htaccess to a 200 code or other, but it seems that I need another exception to exclude the rewrite rule for the filename data swfupload is sending but I don't know where to catch it or even what it is Tongue

excluding the uploads directory from having trailing slashes didn't work either.

Here is my .htaccess for someone geekier than me to solve!

Code:
RewriteEngine on
RewriteBase /

# this adds trailing slash to all but auth and files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !(auth)
RewriteCond %{REQUEST_URI} !(.*)/$
#this works, but kills swfupload file uploads
RewriteRule ^(.*)$ $1/ [R=301,L]
##this works for swfupload file uploads, but stops appening trailing slash
#RewriteRule ^(.*)$ $1/ [L]

RewriteCond $1 !^(index\.php|kyujin\.php|public|tmp|forbidden|restricted|tests|xampp|uploads|robots\.txt|shop_news\/index\.php|shop_news\/index_m\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

Cheers,

Leon
#2

[eluser]TheFuzzy0ne[/eluser]
Hi, Leon!

Sorry, but I am confused. Please could you explain this business with the trailing slash and why it needs to be added? I don't understand what you're trying to achieve.
#3

[eluser]Leon Stafford[/eluser]
[quote author="TheFuzzy0ne" date="1239472486"]Hi, Leon!

Sorry, but I am confused. Please could you explain this business with the trailing slash and why it needs to be added? I don't understand what you're trying to achieve.[/quote]

Hi TheFuzzy0ne,

Thanks for your quick reply.

The adding slashes is something which is required for one of my views to work, and also makes the URLs a bit cleaner. Basically if FreakAuthLight didn't redirect back to the target page without the trailing slash in the original URI I wouldn't need to mess with this in the htaccess.

ie. User isn't logged in and goes to page "test/" which is a valid URI in my app. Because they aren't logged in, FAL takes them to the login screen. After they successfully login, FAL sends them to the original target URI, but drops the trailing slashes, ie sends them to "test".

Of course my clients suck, so I have until Monday to write a big chunk of the backend which means I can either:

1. Code around it in .htaccess (seems to be the quickest)
2. Hack FAL to preserve the trailing slashes in original URI (searching gets me nada in the forums)
3. Hack SwfUpload to not break (seems the least likely to happen by Monday)
4. Take an extended leave of absence from work until the project is forgotten :red:
#4

[eluser]Leon Stafford[/eluser]
Oops, got it!

Adding:

Code:
#only do it for known filetypes which aren't images
RewriteCond %{HTTP_ACCEPT} (text/html|\*/\*)

To the .htaccess will exclude images from getting trailing slashes added.

This seems to work without breaking anything else (so far).

I may need to add some more accepted types besides text/html, but fingers crossed 8-/
#5

[eluser]TheFuzzy0ne[/eluser]
When you say "The adding slashes is something which is required for one of my views to work", what do you mean? Can you give an example? I just don't understand why this is necessary, or if it really is necessary, why the view can't be made aware of this.

Would it not be simpler to just make FreakAuth add the trailing slash? I know it's a bit hacky, but it saves a redirect and of course, messing around with the htaccess file. Don't quote me here, but I think FreakAuth stores the original target URI in the session, so can you not modify it that way?

In theory, htaccess would be the quickest option, but htaccess and I were never the best of friends, so I try to avoid it where possible. Hacking FAL yourself may feel wrong, but I would have thought it would be easier for you to understand what's going on, so that's my suggestion.
#6

[eluser]Leon Stafford[/eluser]
[quote author="TheFuzzy0ne" date="1239474135"]When you say "The adding slashes is something which is required for one of my views to work", what do you mean? Can you give an example? I just don't understand why this is necessary, or if it really is necessary, why the view can't be made aware of this.

Would it not be simpler to just make FreakAuth add the trailing slash? I know it's a bit hacky, but it saves a redirect and of course, messing around with the htaccess file. Don't quote me here, but I think FreakAuth stores the original target URI in the session, so can you not modify it that way?

In theory, htaccess would be the quickest option, but htaccess and I were never the best of friends, so I try to avoid it where possible. Hacking FAL yourself may feel wrong, but I would have thought it would be easier for you to understand what's going on, so that's my suggestion.[/quote]

Thanks again TheFuzzy0ne,

I just posted that I found my code around (aka hack around) with .htaccess . I know the ideal way would be to do it in the program at a lower level, but I was/am in a bit of a pinch and got the trailing slashes added quick with .htaccess so thought it may be able to solve all my problems %-P .

The problem with one of my views sounds like something which should be fixed and it really should and maybe will be, but I have a list of site changes to burn through tonight and I know it's going to suck a lot of my time if I even think about looking at it.

The culprit in question is a page which generates results from db and displays it inline via ajax-y stuff. I'd like to know why it doesn't work without the trailing slash, but besides that, the said page is working fine after a few days of dev. so really don't want to touch it if I don't have to....

I know, not the right way to go about things, but....
#7

[eluser]TheFuzzy0ne[/eluser]
I missed your previous post, so thanks for letting me know about it. I totally agree, you've gotta to do what you've gotta do, and you need to prioritise. Good luck with your project. Smile




Theme © iAndrew 2016 - Forum software by © MyBB