Forum Moderators: phranque

Message Too Old, No Replies

.htaccess troubles

         

workman161

7:37 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



I have a small gallery program on my site. To help save on bandwith, and eliminate the need for me to resize my images, the gallery resises images, and brands them.

Current .htaccess:

RewriteEngine On
RewriteRule ^/[^\?](.*)$ /?$2 [PT,NE]

What I am trying to do is this:

When someone accesses [images.example.net...] then it should redirect to [images.example.net...] See? It adds the question mark. I don't know if the problem is with my hosting provider, or my .htaccess. I don't need anything complex, so you could try using the RedirectMatch directive to do it. The .htaccess is located at [example.net...] and images.example.net maps to /images/. In /images/, there is index.php which does all the image resizing and such.

Could you help me?

[edited by: jdMorgan at 2:57 am (utc) on Nov. 21, 2004]
[edit reason] Removed specifics per TOS. [/edit]

jdMorgan

3:45 am on Nov 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



workman161,

Welcome to WebmasterWorld!

Comment:

> http://images.example.net/?screenies/

This is not a valid URL, but this would be:

http://images.example.net/?screenies

The problem is the trailing slash. It also complicates parsing out the URL, and *may* lead to a redirection loop if you're not careful. This would be the case if you needed to look for the last "subdirectory" in the URL. You'd need to look for the last slash not preceded by a question mark, instead of just looking for the last slash.

Questions:

Why are you using Pass-Through mode? Are you processing the output of this Rule through Alias, ScriptAlias, Redirect, or Redirect Match, i.e. feeding the rewritten URL from mod_rewrite into mod_alias?

Similarly, you shouldn't need to use the NoEscape flag, either.

I'll assume that you simply want to move "screenies" from a directoty-path position in the URL to a query string to be used by your php file, i.e.

http://images.example.net/screenies/ --> http://images.example.net/?screenies

and with DirectoryIndex in the "images" directory set to index.php, the effective URL then becomes
http://images.example.net/index.php?screenies

Then after another run through httpd.conf, you rewrite the subdomain to /images, and end up at
example.net/images/index.php?screenies

In that case, try:


Options +FollowSymLinks
RewriteEngine On
RewriteRule ^screenies/?$ /?screenies [L]

and if "screenies" is a variable, then try:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]+)/?$ /?$1 [L]

Now, this code is not a redirect, it is a rewrite, and that may be affecting things. It might be easier to simply do the whole pile of functions all at once in one place, and use:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]+)/?$ /images/index.php?$1 [L]

This would be much more efficient than having to pass through another rewrite to get to the images subdirectory, and then through mod_dir to look up the index.php default index file. This rewrite does it all at once and gets it over with.

I'm not really sure exactly why you've got these three layers of URL-mapping, and are using PT and NE. But maybe you can play with some of these variants I've posted to see if they fit your needs.

Jim

workman161

8:38 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



Eh... I don't think you quite understand this.

If someone requests [images.example.net...] then I want [images.example.net...] to show up. If they want [images.example.net...] then I want [images.example.net...] to be shown. This is not a dedicated server. This is a hosting account. I would only have access to .htaccess. All 3 of the codes you gave me do not work.

jdMorgan

10:47 pm on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Example two should have worked, or should have been close. I can point you in the right direction, but it's up to you to tweak and tune it. Post specific questions and descriptions of any problems, and we'll try to help.

Also, I'm not sure exactly what you mean by "show up". The code above is an internal rewrite. As such the content served will be from the new URL-path, but the browser address bar will not "show" any change. If you want the browser address bar to update, you'll need to use the external redirect format of RewriteRule.

Our charter [webmasterworld.com] contains links to useful references, as well as information about this forum.

Jim