Forum Moderators: phranque
Options -Indexes
Options +FollowSymLinks
#Rewrite engine
RewriteEngine on
RewriteRule ^product/(\w+)/([0-9]+)$ /index.php?product=$1&pid=$2&sp=1 #REDIRECT ANY PHP REQUEST TO HTM
RewriteRule ^([-0-9a-zA-Z_]+)\.htm$ $1.php [nc] [L]
#BLOCK ANY PHP REQUESTS
#RewriteRule ^(.*)\.php errors/404 [L]
ErrorDocument 404 index.php?pg=error&type=$404 [L]
/index.php?pg=error&type=04 type=04 part. This occurs because the $4 backreference you accidentally used in the rewrite target will be blank. ErrorDocument 404 errors/404 [L]
Options -Indexes
Options +FollowSymLinks
#Rewrite engine
RewriteEngine on
#Main Pages
RewriteRule ^page/([-0-9a-zA-Z_]+)/([0-9]+)$ Pages/$1.php?pid=$2 [L]
RewriteRule ^content/([-0-9a-zA-Z_]+)$ index.php?pg=$1 [L]
RewriteRule ^content/([-0-9a-zA-Z_]+)/([0-9]+)$ index.php?pg=$1&toe=$2 [L]
RewriteRule ^content/contact_gbforklifts/([0-9]+)/([0-9]+)/([0-9]+)$ index.php?pg=contact_gbforklifts&toe=$2&pid=$1&buy=$3 [L]
#News Articles
RewriteRule ^news/([-0-9a-zA-Z_]+)/([0-9]+)$ index.php?pg=news&article=$1&nid=$2 [L]
#Shop
RewriteRule ^categories/([-0-9a-zA-Z_]+)/([0-9]+)$ index.php?cat=$1&cid=$2 [L]
RewriteRule ^categories/([-0-9a-zA-Z_]+)/([0-9]+)/([0-9]+)$ index.php?subcat=$1&scl=$2&cid=$3&child=2 [L]
RewriteRule ^categories/subcat/([-0-9a-zA-Z_]+)/([0-9]+)$ index.php?subcat=$1&cid=$2&spl=1 [L]
RewriteRule ^products/([-0-9a-zA-Z_]+)/([0-9]+)$ index.php?product=$1&pid=$2&sp=1 [L]
#End
#Create 404 Error Page
RewriteRule ^errors/([0-9]+)$ index.php?pg=error&type=$1 [L]
#End
#PHP REQUESTS = ERROR PG
RewriteRule ^([-0-9a-zA-Z_]+)\.php index.php?pg=error&type=404 [L]
#End
#Rewrite sitemap for SEO
RewriteRule sitemap\.xml site-map.php [L]
#End
#REWRITE ANY PHP REQUEST TO HTM
RewriteRule ^([-0-9a-zA-Z_]+)\.htm$ $1.php [NC,L]
#End
#Forward 404 Errors to Error Page
ErrorDocument 404 index.php?pg=error&type=404
#End
A 404 error will show the content at /index.php?pg=error&type=04
Notice the type=04 part. This occurs because the $4 backreference you accidentally used in the rewrite target will be blank.
#REWRITE ANY PHP REQUEST TO HTM
RewriteRule ^([-0-9a-zA-Z_]+)\.htm$ $1.php [NC,L]
#Create 404 Error Page
RewriteRule ^errors/([0-9]+)$ index.php?pg=error&type=$1 [L]
example.com/errors/404 then show the content at /index.php?pg=error&type=404 #Forward 404 Errors to Error Page
ErrorDocument 404 index.php?pg=error&type=404
What it says is this: "if there is an external request for this URL: example.com/errors/404 then show the content at /index.php?pg=error&type=404
When your ErrorDocument directive is triggered it does not make an "external" request for a URL, so this rule will never run.
everything seems to work except #Search and #Rewrites PHP requests to 404 PG.
#Search
RewriteRule ^search/ index.php?pg=search [L]
RewriteRule ^search/([-0-9a-zA-Z_]+)/([a-z]+)/([0-9]+)/([0-9]+)$ /index.php?pg=search&sq=$1&sort_price=$2&rpp=$3&pgn=$4 [L]
RewriteRule ^content/contact_gbforklifts/... RewriteRule ^categories/subcat/... Options lines into one line.