Welcome Guest, Not a member yet? Register   Sign In
Rewrite rule generating Internal Server Error
#11

[eluser]TheFuzzy0ne[/eluser]
Code:
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.domain\.com [NC]
RewriteRule ^/images/(.*)$ images/%1/$1 [L]

I think the problem is a missing forward slash in the regex. I'm still reading, but I'm hoping this might fix your problem. You might need to try adding a forward slash to the rewritten URL too:

Code:
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.domain\.com [NC]
RewriteRule ^/images/(.*)$ /images/%1/$1 [L]
#12

[eluser]johncook[/eluser]
Reading up in the wee hours of the morning, you're a legend! Any time after midnight, my brain is incapable of learning new things so I'm impressed.

Okay, adding the forward slashes at the start of the regex and rewritten URL has removed the Internal Server Error. So good progress!!! :-) It's still weird though. When I used your code exactly as is, what seemed to happen was:

http://cavaliers.criciwiki.com/images/header1.gif >>> http://www.criciwiki.com/images/header1.gif

Eg - it seems to completely ignore the %1 in the rewritten URL. So I tried a few other things:

Code:
RewriteRule ^/images/(.*)$ /images/$1 [L]

This does exactly what you would expect, which is the same as your code. So I tried manually putting a subdirectory in:

Code:
RewriteRule ^/images/(.*)$ /images/cavaliers/$1 [L]

This does the same thing again - it only works for images in the images/ directory. Any time I try an image that's in the cavaliers/ directory, it gives a File Not Found error. Better than an Internal Server Error, I'll grant you that. But strangely, it only seems to be rewriting to the images/ directory.

But the forward slashes definitely fixed the server error, which was a great help! :-)
#13

[eluser]TheFuzzy0ne[/eluser]
Did you try without the forward slash on the rewritten string (the string on the right)?
Code:
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.domain\.com [NC]
RewriteRule ^/images/(.*)$ images/%1/$1 [L]
#14

[eluser]johncook[/eluser]
Yep (tried just about every permutation). Same result with or without forward slash on the rewritten string.
#15

[eluser]TheFuzzy0ne[/eluser]
How about this:
Code:
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.domain\.com$ [NC]
RewriteRule ^/images/(.*)$ /images/%1/$1 [R,L]
#16

[eluser]johncook[/eluser]
Still get file not found error but it does find images in the images/ directory. In other words, redirects to the images/ directory.

As far as I can tell, it just doesn't seem able to redirect to a sub-subdirectory. So I'm just gonna have to settle with this rule:

Code:
RewriteRule ^images/(.*)$ %1/$1 [L]

This successfully renames subdomain.domain.com/images/pic.jpg to www.domain.com/subdomain/pic.jpg

Not the solution I wanted but I'm just gonna have to settle with it. But your persistence is deeply appreciated, we got close :-)
#17

[eluser]TheFuzzy0ne[/eluser]
I'm still working on it, so I will let you know when I get it sorted. At the moment I'm fighting recursion... Sorry it's taking so long. htaccess files have some serious grunt behind them, the main problem is taming that grunt.
#18

[eluser]TheFuzzy0ne[/eluser]
This is what I have so far
Code:
RewriteCond        %{REQUEST_URI}    ^/images [NC]
RewriteCond        %{HTTP_HOST}    !^www\. [NC]
RewriteRule        ^(.+)  %{HTTP_HOST}/$1    [C]
RewriteRule        ^([^.]+).+/images/(.+)$    images/$1/$2 [L]

But it results in some serious recursion, and I don't know why. It's something to do with the second captured parameter. When you insert the file name manually it works.

If anyone can share any insight as to what's happening here, I'd really appreciate it.
#19

[eluser]TheFuzzy0ne[/eluser]
Code:
RewriteCond %{HTTP_HOST} (.+)\.criciwiki\.com$ [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule ^/images/(.*)$ http://www.criciwiki.com/images/%1/$1 [NC]

I'm interested to see if this fixes your issue. It's taken forever to perfect, and works on my machine. Don't worry if it's too late. My brain needed the exercise anyway.
#20

[eluser]johncook[/eluser]
Sorry, this code gives me a broken image error. I've decided to go with the following code:

Code:
RewriteCond %{HTTP_HOST} !^www\.criciwiki\.com
RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.criciwiki\.com [NC]
RewriteRule ^images/(.*)$ %1/$1 [NC]

It means the images go in directories in the root directory rather than the images directory. Not ideal but I can't spend the rest of my life figuring out the bloody rewrite rules. Dunno why this doesn't work on my server but does on yours but I deeply appreciate your valiant efforts. Many thanks!!




Theme © iAndrew 2016 - Forum software by © MyBB