Y
Y
yparah2015-02-05 11:31:14
Apache HTTP Server
yparah, 2015-02-05 11:31:14

How to redirect Apache before it gives a 404 error?

How to redirect Apache to another file using mod_rewrite without declaring a 404 error?
Now .htaccess contains a line like ErrorPage 404 /index.php
Apache processes the error, writes about it to the log and passes control to index.php, which processes the request.
.htaccess content
AddDefaultCharset UTF-8
Options +FollowSymLinks +ExecCGI
ErrorDocument 404 /index.php
RewriteEngine On
#Hides backend and its static content from all domains except 1
RewriteCond %{REQUEST_URI} !^/index.php$ [NC]
RewriteCond %{ REQUEST_FILENAME} -f
RewriteCond %{HTTP_HOST} !^.*$
RewriteRule ^(.*)$ - [R=404,L]
#No script name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zooks, 2015-02-05
@zooks

RewriteRule ^old-path$ new-path [R=301,L]

I
Igor, 2015-02-05
@merryjane

Depending on what condition. Here is an example:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /file_to_rewrite.php [L]
</IfModule>

where %{REQUEST_FILENAME} !-f is not a file,
%{REQUEST_FILENAME} !-l is not a symbolic link,
%{REQUEST_FILENAME} !-d is not a directory,
/file_to_rewrite.php is where to rewrite.
Choose whichever suits you best.
More on RewriteCond:
is a directory

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question