Web Hosting Talk







View Full Version : Mod_rewrite not working properly in Firefox - why???


JavaDziner
02-18-2010, 12:22 PM
I posted a topic a few days ago in another section of the forums...and though I did receive a post in reply to the problem I was having, it wasn't the answer, and the member didn't provide any additional help thereafter.

I am trying to accomplish 2 things, both requiring the use of mod_rewrite. It is installed on my server. I have no experience using mod_rewrite, but have started reading an online tutorial/guide, so I am clearly no expert on it.

What I want to do is this -
1) forward requests for mysitename.com to www.mysitename.com
2) ensure that if a request for www.mysitename.com/Customers/ comes in, that the 'c' in 'Customers' is uppercase, and not lowercase.

I tried the following in an attempt to solve issue #1 -
RewriteCond %{HTTP_HOST} ^mysitename\.com [NC]
RewriteRule ^(.*)$ http://www.mysitename.com$1 [L,R=301]

I typed in mysitname.com in IE - and it worked correctly (http://www.mysitename.com/), but in Firefox it adds an additional trailing slash to the end of the address, like this - http://www.mysitename.com//

I can't understand why Firefox is doing that - and in the RewriteRule I did remove the slash from the site address.

Can someone please provide me with some possible solutions? I am really struggling here, and have nowhere else to go...

mattle
02-18-2010, 01:07 PM
Add:


RewriteBase /


Above the RewriteCond.

What's happening is you are issuing the following HTTP command:

GET /

That is what is being matched by your RewriteRule ^(.*)$ and then appended to the domain. I think IE is just cleaning up the URI for you.

ref: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteBase

JavaDziner
02-18-2010, 03:11 PM
I put the mod_rewrite directives into httpd.conf on my server.

I tried adding Rewrite Base /, but I got this error :
Website configuration is broken:
RewriteBase: only valid in per-directory config files

Are the mod_rewrite directives supposed to go into the .htaccess file or can they go into httpd.conf? I tried putting them in the .htaccess file instead (via my server's control panel) and when I tried accessing my site, I got a page saying "Internal Server Error".

mattle
02-18-2010, 04:53 PM
Nope...you should put them in your <Directory> or <VirtualHost> blocks in your main config file. A lot of posters here are on shared hosting and only have the option to use .htaccess, so I made that assumption...my bad.

JavaDziner
02-18-2010, 05:49 PM
I put the directives in the httpd.conf file, using my control panel, which means they appear under the <VirtualHost> blocks of that file. I checked to verify.

I don't understand why it won't accept the Rewrite Base / part.

I have access to the .htaccess file, and tried putting the directives in there, but get an internal server error in the browser.

Any other ideas? Are there any other mod_rewrite directives I could try?

khunj
02-18-2010, 07:13 PM
2) ensure that if a request for www.mysitename.com/Customers/ comes in, that the 'c' in 'Customers' is uppercase, and not lowercase.

You can do it that way :

RewriteEngine on
RewriteMap UP int:toupper
RewriteCond %{REQUEST_URI} ^/[a-z]
RewriteRule /(.)(.*) ${UP:$1}$2 [R=301,L]

You must add this inside your Apache vhost as it won't work inside an .htaccess.
You may need to tweak it too, because in my sample, any page will have its first letter converted to uppercase (ie: www.mysitename.com/Foobar.html)

JavaDziner
02-19-2010, 10:11 AM
Nope...you should put them in your <Directory> or <VirtualHost> blocks in your main config file. A lot of posters here are on shared hosting and only have the option to use .htaccess, so I made that assumption...my bad.

I tried again this morning to put RewriteBase \ into the httpd.conf file, and again I got this error.

Website configuration is broken:
RewriteBase: only valid in per-directory config files

I don't understand why it won't accept the directive. Rewrite rule's are appearing in the httpd.conf file under the <VirtualHost> block though, but RewriteBase won't take....

Do I have to contact my host provider about this?

JavaDziner
02-19-2010, 11:41 AM
I contacted my host provider and they got back to me just now - problem is solved.

The mod_rewrite directives below go in the httpd.conf file -
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysitename\.com [NC]
RewriteRule ^(.*)$ http://www.mysitename.com$1 [L,R=301]


But the RewriteBase directive must go in the .htaccess file -
RewriteBase /

I would've never known about RewriteBase, and that its the directive needed to solve my problem - thank you mattle!!