Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect directory to a single page

I want to redirect all pages from the .com/blog directory to the .com/error directory.

I have searched the web, and found loads of different ways of doing it, but I want it to redirect to a single page.

All the things I have tried redirect to the same file name, but in different directory. For example, .com/blog/index.nonexisting redirects to .com/error/index.nonexisting.

I would like all files in the first directory to redirect to a certain file, so if you go to .com/blog/whatever.php it would go to .com/error/index.php, and if you go to .com/blog/random.xml you would be redirected to .com/error/index.php.

Is there any way to do this?

like image 663
Marcus Cemes Avatar asked Dec 20 '22 21:12

Marcus Cemes


1 Answers

Try putting this in your .htaccess:

RewriteEngine on
RewriteRule ^blog/(.+) error/index.php [L,R]

Replace R with R=301 if you want a 301 redirect, and get rid of R entirely if you don't want an external redirect.

like image 167
Ansari Avatar answered Dec 28 '22 09:12

Ansari