Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem with existing directory

         

RammsteinNicCage

3:39 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



I have a directory called galleries. I'm trying to rewrite a URL like:

www.example.com/galleries/person/concert/1/

to:

www.example.com/galleries/gallery.php?gallery=person&type=concert&page=1

I can get this to work if I change galleries to something else that doesn't already exist, like:

RewriteRule ^gallery1/([^/]+)/([^/]+)/([0-9]+)/$ /galleries/gallery\.php?gallery=$1&type=$2&page=$3 [L]

Is there some type of conflict because the second part of the rule starts off with /galleries/?

Jennifer

Longhaired Genius

4:00 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Sorry, I cant see what's wrong, except you don't need to escape the dot in the rewrite and, personally, I wouldn't include the final slash.

Does it work if you simplify it right down like:

RewriteRule ^galleries/person/concert/([0-9]+)/$ galleries/gallery.php?gallery=person&type=concert&page=$1 [L]

[edited by: Longhaired_Genius at 4:19 pm (utc) on July 27, 2005]

dcrombie

4:18 pm on Jul 27, 2005 (gmt 0)



Your problem relates to "Content Negotiation" or "MultiViews":

[webmasterworld.com...]

;)

RammsteinNicCage

4:35 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Getting rid of the escape in the rewrite and simplifying it didn't work.

Adding Options -Multiviews didn't work either, but is that something I should keep in there anyway?

Jennifer

Longhaired Genius

5:59 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Are there any other rewrites that might be interfering?

You could try putting your rewrite .htaccess in the galleries directory (changing it where appropriate, of course).

RammsteinNicCage

7:19 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Ok, I guess I've narrowed the problem down. In my galleries directory, I have an .htaccess file that says:

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?domain.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?ipaddress(/)?.*$ [NC]
RewriteRule .*\.(gif¦jpg¦jpeg)$ - [F,NC]

When this file exists, the rewrite in my webroot does not work. When I delete it, the rewrite works. Any ideas why?

Jennifer

Longhaired Genius

8:01 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



That code is to ban hotlinking and it looks alright to me. In my site I have it in the main directory .htaccess above any other rewrites. You could try moving it there. If you do that, and if you have any directories you allow hotlinking from (eg, banners) you have to specifically allow hotlink access to them with a condition like this at the top of the other conditions:

RewriteCond %{REQUEST_URI}!banners/.*$ [NC]

There should be a space between } and!

Options -Multiviews is the default so it doesn't matter if you leave it there.

jdMorgan

9:01 pm on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The new and old URLs need to be different to avoid an 'infinite' rewriting loop. The simplest fix for your code might be to add a RewriteCond:

RewriteCond %{QUERY_STRING} ^$

In this way, once the URL is rewritten with the query string added, the rule will no lonager apply, since the query string won't be blank any more.

Jim