how to make a 301 redirect with rewrite if page dont exist

New to mod_rewrite? This is a good place to start.

how to make a 301 redirect with rewrite if page dont exist

Postby alud » Sun Nov 01, 2009 8:47 am

Hello, I want to know how to make 301 redirect with mod rewrite when a requested page don't exist.

for example if the requested page is:
http://www.site.com/sarasa/kakaka.html and this page don't exists I want to 301 redirect to

http://www.site.com/sarasa/sarasa.html

Kind regards,
alud
 
Posts: 4
Joined: Sat Jul 18, 2009 4:18 pm

Postby richardk » Mon Nov 02, 2009 10:28 am

Just for the /sarasa directory?
If not, will it always need to redirect to /sarasa/sarasa.html, the current directories sarasa.html file or a different file for each directory?

Try the following in /sarasa
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule . /sarasa/sarasa.html [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby alud » Mon Nov 02, 2009 6:33 pm

richardk wrote:Just for the /sarasa directory?
If not, will it always need to redirect to /sarasa/sarasa.html, the current directories sarasa.html file or a different file for each directory?

Try the following in /sarasa
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule . /sarasa/sarasa.html [R=301,L]


Thanks a lot...
Let me explain what I'm trying to do. I have many sites that link to my site, this sites sometimes link to incorrect pages, for example: www.sites.com/sarasa/onepage.html and maybe onepage.html doesn't exist so I want to redirect in a 301 way to www.site.com/sarasa/sarasa.html. I that way I don't loose pr...
For other case I'll use the custom 404 page...

this script cover that? if not could you please, help again?

thanks a lot,
alud
 
Posts: 4
Joined: Sat Jul 18, 2009 4:18 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 28 guests

cron