0

I'm using htaccess from stackoverflow.com/q/8583856 -

RewriteEngine on
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.mysite.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://www.mysite.com/profile.php?u=$1 [NC]

Everything works great unless I type www.mysite.com into address bar -    
returns mysite.com/profile?u=index.html.var  
which errors "Unknown column index.html.var in where clause"  

Anyone know how to get this to go to mysite.com/index instead?

JSwiss
  • 11

2 Answers2

0

Change your code to this and let me know how it behaves (after clearing your browser cache):

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=302,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ $1 [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ profile.php?u=$1 [NC,L]

Once you're sure it is working then change R=302 to R=301

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks, anubhava! Works great. I wish I would have gotten this 17 hours ago when you sent it. Stack didn't notify me. – JSwiss Mar 06 '12 at 04:43
0

try adding a condition to check if the path is empty (i.e. root)

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond $0 ^$
RewriteRule .* - [L]
Gerben
  • 16,747
  • 6
  • 37
  • 56