Degauser
Degauser

Reputation: 120

htaccess Redirect One File to Another

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.

Upvotes: 8

Views: 13296

Answers (1)

Jon Lin
Jon Lin

Reputation: 143896

Try:

RewriteEngine On
RewriteRule ^(header|content|footer)\.php - [L,R=404]

or

RewriteEngine On
RewriteRule ^(header|content|footer)\.php index.php [L,R=301]

Upvotes: 7

Related Questions