0

I have URL rewrite rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L]

When this URL is called: http://example.com/suyash

It internally calls http://example.com/sites/suyash but keeps the URL as http://example.com/suyash only. Please note that the folder sites/suyash actually exists

The issue I am facing is that when I call a URL: http://example.com/Suyash (Uppercase) it shows a 404 error.

When I use the mod_speling module and add the following to the code:

CheckSpelling On

and now when I call http://example.com/Suyash it changes the URL to http://example.com/sites/suyash

How do I get it to only change URL from http://example.com/Suyash to http://example.com/suyash?

unor
  • 92,415
  • 26
  • 211
  • 360
Suyash
  • 625
  • 1
  • 5
  • 22

2 Answers2

0

mod_speling will redirect the browser in order to fix spelling, there's no way to avoid this. The only thing I can think of is to try proxying the request internally by using the P flag. You'll need to make sure you have mod_proxy loaded. I haven't tested this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L,P]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
0

I would say keep CheckSpelling off.

And then have your rule like this:

CheckSpelling Off
RewriteEngine On
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/$0 -f [NC]
RewriteCond %{DOCUMENT_ROOT}/$0 -d [NC]
RewriteCond %{REQUEST_URI} !^/sites/ [NC]
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643