jokerfool Posted February 14, 2013 Share Posted February 14, 2013 If I have a link that keeps appearing in search engines thats wrong and goes no where, can I use the redirect in the htaccess file to specify wildcards e.g. http://www.domain.com/abc/blah/123.html to redirect any link within /abc/ to go back to domain.com? I know I can set up Redirect 301 http://www.domain.com/abc/123/asdf.html http://www.domain.com But can I do Redirect 301 http://www.domain.com/abc/* http://www.domain.com Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/274486-domainfolderfile-redirect-htaccess/ Share on other sites More sharing options...
kicken Posted February 14, 2013 Share Posted February 14, 2013 (edited) The value you give Redirect is just a prefix, so if you wanted to redirect everything under http://www.domain.com/abc/ you can just do Redirect 301 /abc/ http://www.domain.com Note however that if someone requested http://www.domain.com/abc/123/asdf.html, it will keep the part after the prefix and append it to the new url, so the redirect would attempt to send them to http://www.domain.com/123/asdf.html. To strip the value, you'll need to use mod_rewrite and a rewrite rule. That said, if that content does not exist anymore, a redirect like that is not what you want to send. You want to send a 410 (Gone) status so that the search engines will stop trying to access that URL and remove it. Sending a 410 makes it so you can't send a new location for the redirect also, but you could configure an ErrorDocument for 410 that will do a redirect using a meta refresh. ErrorDocument 410 /errors/410.html Redirect 410 /abc/ Then in /errors/410.html <html> <head> <title>410 Gone</title> <meta http-equiv="Refresh" content="5;url=http://www.example.com/"> </head> <body> <p>The document you requested has been removed. Please <a href="http://www.example.com/">return to the home page</a></p> </body> </html> Edited February 14, 2013 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/274486-domainfolderfile-redirect-htaccess/#findComment-1412447 Share on other sites More sharing options...
jokerfool Posted February 19, 2013 Author Share Posted February 19, 2013 In Google there are hundreds of *.html files that are indexed, is there an easy way for me to redirect those links to those html files whatever they may be to the main domain? Redirect 301 /abc/ http://www.domain.com Cant I use wildcards or something? Redirect 301 /abc/* http://www.domain.com Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/274486-domainfolderfile-redirect-htaccess/#findComment-1413294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.