1

I have created a .htaccess file that allows for vanity URLs. However, I am no longer able to type www.website.com without typing in the index file. I.e. I have to type in www.website.com/index.php in order to see the homepage. This is what my .htaccess file looks like:

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

Anyone know how to fix this? Thank you all!

1
  • Is this .htaccess file on www.website.com host's document root? Commented Dec 9, 2012 at 3:40

2 Answers 2

4

The way you defined your rule increased the complexity.

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

Above rule means if file name is a directory of file process as it is. after that dont process farther.

RewriteRule ^(.*)$ http://www.website.com/profile.php?u=$1 [NC]

This rule means map any request uri to profile.php?u=

Now when you request / that is www.website.com it checks the first rule and it fails to match. Then it check the second rule and maps it to profile.php?u=.

  1. One way to fix it, would be check *if $_GET['u'] is empty or / in profile.php. If it is then load the index.php.
  2. Another way is to find a proper regular expression for your user names once found use it here.

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(USERNAME_REGEX)$ http://www.website.com/profile.php?u=$1 [NC,L]
    

The best way to handle this is using PHP,

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?uri=$1 [L]

Now index.php will get every uri you pass. Now you can process the URI in index.php.

Sign up to request clarification or add additional context in comments.

Comments

2

It may be due to your server set up. Try DirectoryIndex index.php (see http://davidwalsh.name/directory-index-homepage-htaccess )

Edit (due to me not reading the question properly in the first place)

Have you tried it without the RewriteRule .* - [L] line?

2 Comments

If that was the case. www.website.com would not have worked before he added the .htaccess but he clearly says it no longer works.
My apologys, lack of concentration hits again. Have you tried it without the RewriteRule .* - [L] line?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.