HTACCESS 500 internal server error website gone down - php

I made a minor change in my .htaccess file and I'm now receiving a 500 internal server error. I changed it back to how it was before the error but, the error is still there.
Here is the file:
ErrorDocument 404 /404-error-page.php
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^dsa-office /(.*)/ dsa_office.php?location=$1
RewriteRule ^([^/\.]+)/?$ /$1.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /$1.php?location=$2 [L]
I edit one of the last 3 lines. Any ideas? Thanks

This rule looks suspicious:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^dsa-office /(.*)/ dsa_office.php?location=$1
It has space in the matching patter between ^dsa-office and /(.*)/
Change this rule to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^dsa-office/(.*?)/?$ dsa_office.php?location=$1 [L,QSA]

Related

combining multiple htaccess rules

i have a htaccess rule that remove .php extension:
`RewriteEngine On
ErrorDocument 403 "Page not exist"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]`
the htaccess rule below redirects to stream.php file:
`RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /core/musicbox/stream/?tag=$1 [NC,L,QSA]`
Both rule works individually, but when combined,the rule placed below does not work.
You have the same conditions twice:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Which means:
!-f: File %{REQUEST_FILENAME} doesn't exist.
!-d: Directory %{REQUEST_FILENAME} doesn't exist.
If both are true and the next one (in the first set of rules) is also true:
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
Then the next rule will do a 301 redirect (R=301) and stop processing rules (L).
RewriteRule (.*)$ /$1/ [R=301,L]
Actually, maybe there's a missing ^ in there. It should be:
RewriteRule ^(.*)$ /$1/ [R=301,L]
Anyway, that means that the second set of conditions and the subsequent rule won't be reached:
RewriteRule ^(.*)$ /core/musicbox/stream/?tag=$1 [NC,L,QSA]
Probably you don't need those first R=301 and L flag. I think this is how it should look like:
RewriteEngine On
ErrorDocument 403 "Page not exist"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ /$1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /core/musicbox/stream/?tag=$1 [NC,L,QSA]

Query string URL prduces 500 internal error after removing .php extension through htaccess

Using .htaccess file on the root I removed .php extension from the url using the code below -
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?foobar.com$
RewriteCond %{REQUEST_URI} !^/foobar/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /foobar/$1
RewriteCond %{HTTP_HOST} ^(www.)?foobar.com$
RewriteRule ^(/)?$ foobar/index.php [L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I have the above code in htaccess. But when ajax calls are made as below -
foobar.com/user/get/?a=getTaggedUsers&forumId=368
This produces 500 interal server error.
If I remove the last line in .htaccess file i.e -
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Then the above query-string url works fine. But now I have to put .php extension too in the url. So how to make query string work without php extension?
Have your code like this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?foobar\.com$
RewriteCond %{REQUEST_URI} !^/foobar/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ foobar/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?foobar\.com$
RewriteRule ^/?$ foobar/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([^.]+)/?$ $1.php [L]

Mod_rewrite, with exception that refers to another rule

i want to use mod_rewrite on my page and already have some rules
now i want to redirect to artist.php?name=(PARAMETER) except it matches another rule
at the moment i use a "a/" before artist.php because i dont know how to solve this problem
so if i want so see the artist "Alex" ist just have to type domain.com/Alex and if i want to go to the about page i just have to type domain.com/about (just like facebook or twitter)
of course i'm thankfully for each improvement
Here is the .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^cover/([0-9]*)(s|m)?\.jpg$ /cover.php?id=$1&size=$2
RewriteRule ^dl/([^/]*)/([^/]*)$ /download.php?$1=$2
RewriteRule ^track/([^/]*)\.mp3$ /song.php?id=$1
RewriteRule ^my(/)([^/]*)$ /my.php?requested=$2
RewriteRule ^album/(.*)-([0-9]{0,6})$ /album.php?id=$2
RewriteRule ^a/([^/]*)$ /artist.php?name=$1
RewriteRule ^a/([^/]*)/music$ /music.php?name=$1
RewriteRule ^(artists|about|charts|contact|myprofile|editprofile|mymusic|uploadsongs|logout|genres)$ /$1.php
RewriteRule ^t$ /t.php
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com(/)?.*$ [NC]
RewriteRule .*\.(mp3)$ - [F,NC]
ErrorDocument 404 /errors/404.php
p.s.: i'm sorry for my bad english
You need to rearrange some of your rules, and add L flags so they don't accidentally get applied:
RewriteEngine On
RewriteBase /
RewriteRule ^cover/([0-9]*)(s|m)?\.jpg$ /cover.php?id=$1&size=$2 [L]
RewriteRule ^dl/([^/]*)/([^/]*)$ /download.php?$1=$2 [L]
RewriteRule ^track/([^/]*)\.mp3$ /song.php?id=$1 [L]
RewriteRule ^my(/)([^/]*)$ /my.php?requested=$2 [L]
RewriteRule ^album/(.*)-([0-9]{0,6})$ /album.php?id=$2 [L]
RewriteRule ^a/([^/]*)$ /artist.php?name=$1 [L]
RewriteRule ^a/([^/]*)/music$ /music.php?name=$1 [L]
RewriteRule ^(artists|about|charts|contact|myprofile|editprofile|mymusic|uploadsongs|logout|genres|t)$ /$1.php [L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com(/)?.*$ [NC]
RewriteRule .*\.(mp3)$ - [F,NC]
# assume anything else is a username
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /artist.php?name=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/music$ /music.php?name=$1 [L]
ErrorDocument 404 /errors/404.php

.htaccess RewriteRule error

I have these lines in .htaccess.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Now, I'd like to add the following into the .htaccess, so I can redirect all users to http://www.mydomain.com
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
So, I just added the code above in my existing .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteRule . index.php
But, It doesn't work as I expect.
Please teach me how I am supposed to write in this case.
Thanks so much in advance!!
You should redirect to the www subdomain first, then forward the request to your index.php file. Try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.).+$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Configure mod_rewrite to add "www" and to support MVC

I would like to add www into the URL if the users forgot to type and still supporting MVC by redirecting to the index.php with [QSA]
This is my current working .htaccess
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
Using this .htaccess everything works fine, I can type www.abc.com/xxx/yyy to visit any specific pages
Anyway because I'm using Facebook authentication so I must prevent my users from typing the site URL without www, so I tried to edit my .htaccess
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteRule ^(.*)$ http://wwww.abc.com/$1 [R=301,QSA]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
With this configuration if I typed abc.com I was redirected to www.abc.com, but if I typed abc.com/xxx/yyy I was only redirected as www.abc.com instead of being redirected to the specific page.
I also tried
# 1
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteRule ^(.*)$ http://wwww.abc.com/$1 [QSA]
# 2
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteRule ^(.*)$ http://wwww.abc.com/index.php [QSA]
# 3
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://wwww.abc.com/$1 [L,QSA]
None of them is working, please guide what to do
Thanks.
Add this 2 lines above your .htaccess file
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
so your final htaccess will look like this
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]

Categories