Search code examples
regexapache.htaccessmod-rewriteinternal-server-error

Error 500 while using htaccess


I can't use a sub domain in my site. It is returning as:

error 500 , internal server error.

When I checked, I found that the problem was with my htaccess file.

RewriteEngine On
Options -Indexes

RewriteRule    ^contest/?$    contest.php    [NC,L]
RewriteRule    ^contest/(.+)/?$    contest.php?name=$1&id=htapappu    [NC,L]

RewriteRule    ^news/?$    news.php    [NC,L]
RewriteRule    ^news/(.+)/?$    news.php?newsid=$1    [NC,L]

RewriteRule    ^projects/?$    projects.php    [NC,L]
RewriteRule    ^projects/(.+)/?$    projects.php?projectid=$1    [NC,L]

RewriteRule    ^page/?$    page.php    [NC,L]
RewriteRule    ^page/(.+)/?$    page.php?feed=$1    [NC,L]

RewriteRule    ^photos/?$    photos.php    [NC,L]
RewriteRule    ^photos/(.+)/?$    photos.php?catg=$1    [NC,L]

RewriteRule    ^profile/complete/?$    complete_profile.php    [NC,L]

RewriteRule    ^profile/picture/?$    set_profile_pic.php    [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ member.php?userismnob=$1&redirect=me    [NC,L]

The problem is in last line.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ member.php?userismnob=$1&redirect=me    [NC,L]

When I remove the last two lines, There is no problem. I think it is a small problem.


Solution

  • You can load index.php by default using DirectoryIndex directive and then add a rule to ignore all rewrites for your subdomaon:

    DirectoryIndex index.php
    Options -Indexes    
    RewriteEngine On
    RewriteBase /
    
    # ignore further rules for admin
    RewriteCond %{HTTP_HOST} ^admin\. [NC]
    RewriteRule ^ - [L]
    
    RewriteRule    ^contest/?$    contest.php    [NC,L]
    RewriteRule    ^contest/(.+)/?$    contest.php?name=$1&id=htapappu [NC,L,QSA]
    
    RewriteRule    ^news/?$    news.php    [NC,L]
    RewriteRule    ^news/(.+)/?$    news.php?newsid=$1    [NC,L]
    
    RewriteRule    ^projects/?$    projects.php    [NC,L]
    RewriteRule    ^projects/(.+)/?$    projects.php?projectid=$1 [NC,L,QSA]
    
    RewriteRule    ^page/?$    page.php    [NC,L]
    RewriteRule    ^page/(.+)/?$    page.php?feed=$1 [NC,L,QSA]
    
    RewriteRule    ^photos/?$    photos.php    [NC,L]
    RewriteRule    ^photos/(.+)/?$    photos.php?catg=$1    [NC,L,QSA]
    
    RewriteRule    ^profile/complete/?$  complete_profile.php [NC,L]
    RewriteRule    ^profile/picture/?$   set_profile_pic.php  [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ member.php?userismnob=$1&redirect=me [NC,L,QSA]