Mod Rewrite generating 500 internal error on page - apache

For some reason my .HTACCESS file won't re-write my users page, even though I'm sure the code to re-write it is correct.
I want to turn
http://www.tfreeb.com/user/user?user=duenna
Into
http://www.tfreeb.com/user/duenna
And this is my HTACCESS file, could it be that something else is conflicting with it?
The re-write rule for the user page is right at the bottom.
Options -Indexes
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
php_value error_reporting 32767
ErrorDocument 404 /notfound.html
ErrorDocument 403 /403.html
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.tfreeb.com$ [NC]
RewriteRule ^(.*)$ http://www.tfreeb.com/$1 [L,R=301]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{HTTP_HOST} ^213\.143\.20\.122
RewriteRule (.*) http://www.tfreeb.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
RewriteRule ^user/([^/]*)$ /user/user.php?user=$1 [L]

After:
RewriteRule (.*) http://www.tfreeb.com/$1 [R=301,L]
Try with that:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^user/([^/]*)$ /user/user.php?user=$1 [NC,L]
RewriteRule ^([^.]+)$ $1.php [NC,L]
No need to use multiple times RewriteEngine On

Are you sure that the .htaccess is being read?
I'd try to make a basic redirect to some page, p.e. google.com if this doesn't work you should ask to the web server admin to give you the AllowOverride = all directive for the directory.
p.e.
<directory /var/www/mysite>
AllowOverride = all
</directory>

Related

htaccess redirect directory to single page in same directory

All attempts failed... I want http://olex-design.at/journal to to be redirected to http://olex-design.at/journal/alle through .htaccess.
So far I have the following - non working - rule in place which produces a 403 forbidden page.
RewriteRule ^journal/$ /journal/alle [R=301,L]
The .htaccess file is placed in the root directory. Maybe someone can point me towards the right direction...
All rules in .htaccess files:
Options -Indexes -MultiViews
RewriteEngine on
#Force non-www:
RewriteCond %{HTTP_HOST} ^www\.olex-design\.at [NC]
RewriteRule ^(.*)$ http://olex-design.at/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]
RewriteRule ^journal/$ /journal/alle [R=301,L]
ErrorDocument 404 /404
With the support of my webhost I was able to resolve my issues described above. This is the complete code in my .htaccess file.
Please note that the first 4 lines did the trick. The code below is responsible to remove the "www", remove the "index" when your in home (http://olex-design.at) and remove the .html file extension.
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^journal\/?$ "http\:\/\/olex\-design\.at\/journal\/alle" [R=301,L]
AddDefaultCharset utf-8
Options -Indexes -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.olex-design\.at [NC]
RewriteRule ^(.*)$ http://olex-design.at/$1 [L,R=301]
<IfModule mod_rewrite.c>
#index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/
RewriteRule ^index\.html$ http://olex-design.at/ [R=301,L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

redirecting homepage without affecting other rules

My current .htaccess is given below.
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
# Send request via index.php (if it's not an existing file/folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I want to redirect my homepage to another domain, but maintain all the /sub/directories.
So changed the rules as below.
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
# Send request via index.php (if it's not an existing file/folder)
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#redirect
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://example.com/ [L,R=301]
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Now all the /sub/directories are getting internel server error. Logs suggesting it's going on loops.
Any idea?
RewriteCond is only for the next RewriteRule.
Use that:
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
#redirect
RewriteRule ^$ http://example.com/ [L,R=301]
# Send request via index.php (if it's not an existing file/folder)
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Trailing slash at end of URL bug .htaccess

My problem is, when I enter http://example.com/admin/ it works well, $_GET['decode'] contains right information and I can work with it. But when I enter http://example.com/admin (without slash), my URL redirects to http://example.com/admin/?decode=admin and everything is messed up. Could someone helps me?
Here is my .htaccess:
RewriteEngine on
Options +FollowSymlinks
<FilesMatch "(config.php|defines.php|functions.php)">
Order Allow,Deny
Deny from all
</FilesMatch>
Header set X-UA-Compatible "IE=Edge,chrome=1"
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([^\.]+)$ ./index.php?decode=$1 [L,QSA]
php_value date.timezone "Europe/Bratislava"
It is because mod_dir is adding a trailing slash in the directory URI (/admin) after your last rule is run by mod_rewrite.
Try this code:
DirectorySlash Off
RewriteEngine on
Options +FollowSymlinks
<FilesMatch "(config.php|defines.php|functions.php)">
Order Allow,Deny
Deny from all
</FilesMatch>
Header set X-UA-Compatible "IE=Edge,chrome=1"
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,NE,L]
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(.*?)[^/][?\s]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ ./index.php?decode=$1 [L,QSA]
php_value date.timezone "Europe/Bratislava"

Redirect entire directory with htaccess

I can't figure out why my redirects aren't working as they are in another htaccess file.
I'm trying to redirect old urls to new ones.
RewriteEngine on
AddDefaultCharset UTF-8
DirectoryIndex index.php index.html
<IfModule mod_php.c>
php_flag magic_quotes_gpc off
</IfModule>
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule (.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Redirect /private_3 http://website.com/new_private
I've tried all sorts of things that I've found on the web but nothing works.
Please help.
Thanks.
Instead of using this:
Redirect /private_3 http://website.com/new_private
Try adding this right below the RewriteEngine on line:
RewriteRule ^private_3(.*)$ http://website.com/new_private$1 [L,R=301]
Looks bad ordering and mixing of mod_alias with mod_rewrite might be a problem here. Try reordering your rules as this:
AddDefaultCharset UTF-8
DirectoryIndex index.php index.html
<IfModule mod_php.c>
php_flag magic_quotes_gpc off
</IfModule>
RewriteEngine on
RewriteRule ^private_3 http://website.com/new_private [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteRule ^(system.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1

.htaccess 301 redirect issue

I need 301 redirect from example.com to www.example.com. This is working solution, but when
I paste it in whole .htaccess site go down.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Rest .htaccess file
php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
php_flag register_globals off
RewriteEngine On
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [L]
Options -Indexes
AddDefaultCharset windows-1251
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(service|news|search|project)/?$ index.php?menu=$1
RewriteRule ^error/([0-9]+)/?$ index.php?menu=error&loadinfo=$1
RewriteRule ^page/([0-9]+)/?$ index.php?menu=page&loadinfo=$1
RewriteRule ^news/([0-9]+)/?$ index.php?menu=news&loadinfo=$1
RewriteRule ^news/page-([0-9]+)/?$ index.php?menu=news&page=$1
RewriteRule ^service/([0-9]+)/?$ index.php?menu=service&category=$1
RewriteRule ^service/([0-9]+)/([0-9]+)/?$ index.php?menu=service&category=$1&loadinfo=$2
RewriteRule ^project/([0-9]+)/?$ index.php?menu=project&loadinfo=$1
Whats the AllowOverride value of the folder where you have your .htaccess? Your DocumentRoot (or VirtualHost) specification needs to be set to at least AllowOverride Options in order to allow php_flag within .htaccess files.
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]