Error document 404 "message" directive not working in .htaccess - php

I do anything for a few days, .htaccess 404 does not work. I tried hundreds of methods, but I did not get it again
this my httaccess :
RewriteEngine on
ErrorDocument 404 "test comment"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://spahan.ir/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^www\.spahan\.ir$
RewriteRule ^/?$ "https\:\/\/spahan\.ir\/" [R=301,L]
RewriteCond %{HTTPS_HOST} ^spahan.ir [NC]
RewriteRule ^(.*)$ http://www.spahan.ir/$1 [L,R=301,NC]

Related

Url-rewriting with multiple parameters

DirectoryIndex /home.php
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/([0-9]+) product.php?id=$1&product_name=$2 [L,QSA]
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
I have this .htaccess file when i try this with 1 parameter it works but with 2 it doesnt work and i want to turn this product.php?id=1&p_name=exmpl link into product/1/exmpl with the above code i have to write this product/1/exmpl with my hand

Nice url with htaccess with specific parameters

I want to have this form of URL : https://domain(:port)/lang/x/y/z/other
With this htaccess file, I can't achieve exactly what I want.
If I enter the URL https://localhost:port/lang/, I lose the port.
If I enter the URL https://localhost:port/lang, i got the URL https://localhost:port/langx/y/z
Please help me!
Options +FollowSymLinks
RewriteEngine On
#LIVE
RewriteBase /
#--------------------------------------
#-- 404 & 500 Redirects
#--------------------------------------
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
#--------------------------------------
#-- Force HTTPS
#--------------------------------------
RewriteCond %{HTTP_HOST} !=localhost$ [NC]
RewriteCond %{SERVER_PORT} !=8088
RewriteCond %{SERVER_PORT} !=8080
RewriteCond %{HTTPS} !=on
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(actions)($|/) - [L]
#--------------------------------------
#-- Add trailing PHP and Params
#--------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.php?param1=$2&param2=$3&param3=$4&param4=$5 [B,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ $1.php?param1=$2&param2=$3&param3=$4 [B,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)$ $1.php?param1=$2&param2=$3 [B,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#check for the existance of a PHP file first or else the 404 won't work
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)$ $1.php?param1=$2 [B,QSA,L]
RewriteRule ^(.*)/$ $1 [R=301,L]

.htaccess to hide extension for both html and php files

I'm working on some PHP pages for a client and I run into a problem.
He likes links for his website to be http://www.website.com/about (without the extension). In his .htaccess is this code:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.website.com/$1 [R,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
Now, the pages i'm making are having extension of php and there is my problem. I have tried several different variations of .htaccess and nothing seems to work. If there is contact.html the URL will be /contact, but if i rename that contact.html page to contact.php and i open /contact page again it is showing me 404 page.
I tried several .htaccess and they are:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_URI} \.((html)|(php))$
RewriteRule ^(.*)\.([^.]+)$ $1 [R,L]
another one:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.website.com/$1 [R,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
I tried more, but they are all gone now. Basically, nothing is working and I don't know what the problem is.
Any help would be awesome...

.htaccess not redirecting home page

Here is my .htaccess on a Linux system:
ErrorDocument 401 ./error/
ErrorDocument 403 ./error/
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.website.co.uk/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L]
Everything works as it should; www is added to non-www requests and a trailing slash is added. However when visiting www.website.com (which is added as a parked domain on cPanel) the user is NOT redirected to www.website.co.uk
If the visit website.com (note no www) then they ARE redirected.
What do I need to add/change in .htaccess?
Have your rules like this:
ErrorDocument 401 ./error/
ErrorDocument 403 ./error/
RewriteEngine on
RewriteBase /
# if not www.website.co.uk then redirect to it
RewriteCond %{HTTP_HOST} !^www\.website\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.website.co.uk/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ http://www.website.co.uk/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

HTACCESS 500 internal server error website gone down

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]

Categories