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,
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) /sarasa/sarasa.html Code (markup): If the directory or file does not exist then it uses /sarasa/sarasa.html However be careful as the content of /sarasa/sarasa.html will show for every unknown URL and return that the page is present (200 status code). At a guess I'd imagine this will cause havoc with search engines. A custom 404 page may be a better idea: ErrorDocument 404 /sarasa/sarasa.html That would show the page you want but return a 404 status code so search engines etc know the page isn't present but visitors still see a nice page to select where to go next.
dear @tolra 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,
Actually I made a typo, my apologies, it should have been: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) /sarasa/sarasa.html [L,R=301] Code (markup): That should 301 any missing page to a single given page, in this case /sarasa/sarasa.html, you should never get a 404. No idea how search engines will view this, but should be interesting to find out