htaccess Redirect One File to Another
11,731
Try:
RewriteEngine On
RewriteRule ^(header|content|footer)\.php - [L,R=404]
or
RewriteEngine On
RewriteRule ^(header|content|footer)\.php index.php [L,R=301]
Related videos on Youtube
Author by
Degauser
Updated on September 14, 2022Comments
-
Degauser about 1 year
I've read this and this seems too long for my request.
And tried
Redirect /index.php /index2.php
but it didn't work (Internal Server error)What I want is to redirect some of my php files to index. For example, I've my index file as
header.php
content.php
footer.php
and I want to redirect direct access to this files to index.php. Is it possible with htaccess or any other way?
mysite.com/index.php OK mysite.com/header.php redirect to 404 or index or something else.
-
Degauser over 9 yearsthanks for your answer. I did RewriteRule ^(header|content|footer)\.php index.php [L,NC] and seems ok. Should I use parameters such ac 301 404 etc? Are they neccesary?
-
Jon Lin over 9 years@Degauser the "R" flag redirects. The 404 means return a "404 Not Found" error, the 301 means permanently redirect.