How can I resolve these vbulletin 404 errors using htaccess? - .htaccess

I have a very big forum (230k threads, 3 million posts) that has a large number of 404 pages reported on Google Webmaster Tools, to the tune of about 14,000 404 URLs. Google is probably showing these 404s because I have incoming links to them, meaning I'm losing a lot of SEO benefit by not having these links follow through to the actual page.
I know why I have this problem, a year ago the URLs on my site were changed back to vBulletin default so that they look like this:
http://www.domain.com/showthread.php?t=323653&p=4230256
I would like to keep them this way since they've been that way for a year. The problem is that there were two previous formats that are showing 404 errors:
These:
http://www.domain.com/forums/showthread.php?t=21461
http://www.domain.com/forums/showthread.php?t=16187
Which just need to have forums/ removed from the URL, and these:
http://www.domain.com/forums/f8/39840-infractions_system_how_works.html
http://www.domain.com/forums/f11/67410-viewing_ijji_gunz_replays_while_offline.html
Which are a funky URL structure that was created back when I had vbSEO installed.
/forums/ needs to be removed and I think that the numbers 39840 and 67410 are probably the thread id. I think there's everything we need in the URL to rewrite but I'm not entirely sure how to achieve it using htaccess.

Assuming, your .htaccess is located at website root "/"
RewriteEngine on
RewriteBase /
# removes "forums/"
RewriteCond %{REQUEST_URI} !^/showthread.php$ [NC]
RewriteRule ^forums/([^/]+)$ $1 [R=301,NC,L]
# parses thread id
RewriteCond %{REQUEST_URI} !^/showthread.php$ [NC]
RewriteRule ^forums/[^/]+/(\d+)-.*$ showthread.php?t=$1 [R=301,NC,L]

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# to redirect /forums/f8/39840-something.html to
# /showthread.php?t=39840
RewriteRule ^forums/[^/]+/([^-]+)-[^.]+\.html$ /showthread.php?t=$1 [R=301,NC,L,QSA]
# to redirect /forums//showthread.php?t=39840 to
# /showthread.php?t=39840
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forums/([^/]+)/?$ /$1 [R=301,NC,L]

Related

How do I redirect to all pages to be a subdirectory of another website but keep the URLs the same?

I have a website that has been built at say montypython.netlify.app
The client has their main website at holygrail.com and they want holygrail.com/resources to show the contents of montypython.netlify.app but keep the URL the same. Which means that it should continue to show holygrail.com/resources in the search bar.
This also means that any pages from montypython.netlify.app should appear are subdirectories of holygrail.com/resources
Example:
montypython.netlify.app/about should appear as holygrail.com/resources/about
I am guessing this has to do with editing the .htaccess at holygrail.com but what rewrite/redirect rules can I reference? There are a lot of URLs so is there a wildcard approach I can use?
This is what I've tried:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^holygrail\.com$ [NC]
RewriteRule ^resources/(.*)$ https://montypython.netlify.app/$1 [R=301,L]
</IfModule>
You can use the [P] proxy flag of mod_rewrite.
Using [P] flag instructs mod_rewrite to handle the request via mod_proxy. Therefore, you must enable mod_proxy to use flag.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^holygrail\.com$ [NC]
RewriteRule ^resources/(.*)$ https://montypython.netlify.app/$1 [P]
</IfModule>
with this code snippet, all pages to be a subdirectory resources will be served from https://montypython.netlify.app/ without a 301 redirection.
Maybe your issue is with the line:
RewriteCond %{HTTP_HOST} ^holygrail\.com$ [NC]
Maybe you need to try to do something like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^resources/(.*)$ https://montypython.netlify.app/$1 [R=301,L]
</IfModule>
I have worked on projects in the past with similar objectives. I don't believe you can accomplish this with redirects. The suggestion about using a reverse proxy would be the most well aligned with your requirements, but there is another option that may also be useful. Some DNS providers offer "DNS Cloaking" or "Stealth Redirects". This can be configured so that requests for holygrail.com will display a frame containing the content for montypython.netlify.app. Could you use the same approach for the /resources sub-directory, so that holygrail.com/resources delivers a frame that loads montypython.netlify.app?
The drawback to this is the address bar will not change as you navigate inside the frame, e.g. navigating to montypython.netlify.app/resources/about will still show holygrail.com/resources in the address bar, because it is displaying the address of the frame.

htaccess - Rewrite URL to remove original filename and replace with GET value

I'm currently using the following htaccess to remove .php extension from all files:-
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
DirectoryIndex start.php?
On my start.php page I have a GET form (action="start") for the user to select there country (start?Country=USA).
Is it possible to rewrite URLs only on the start page to show the URL as mysite.com/USA? (removing "start?Country=" but including the question mark at the end of the URL) or will this conflict with the DirectoryIndex rule?
I've tried lots of different code I've found online but none of it seems to do what I need (and usually results in internal server errors).
Cheers for any pointers =)

redirect request uri to mirror site using htaccess

I have a website. I created a mirror of it and uploaded it in a directory called 'mirror'. What I wanted to do is whenever a viewer access for example..
http://www.example.com/this-page/another-segment/?id=1
I want him to be redirected to..
http://www.example.com/mirror/this-page/another-segment/?id=1
^^^^^^
(I am doing this because I want to want to edit my site's design but I don't want viewers to see the changes in progress until they are complete. Thus I want to redirect them to the mirrored snapshot, at least temporarily.)
Please suggest how this can be done using .htaccess or not.
after browsing around the internet. i came up with the idea of putting a /$1, a rewritebase and followsymlinks on the answer givien by appclay
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/mirror/
RewriteRule (.*) /mirror/$1 [R=301,L]
You'll want to do something like:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/mirror/
RewriteRule ^/(.*) /mirror/$1 [R]
In your .htaccess file.

mod_rewrites .htaccess not working with godaddy hosting (linux)

On my site www.sqcp.com in testing on another linux server, all worked as it should. However since moving it to godaddy, the mod_rewrites haven't been working, therefore none of the other pages have been accessible. Even if I create a blank directory/folder in the what it's trying to tidy the url to it then works for that page (obviously isn't a fix).
So any help would be great here my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ / [L,R=301]
RewriteRule (.*)/{2,}$ /$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteRule ^(.*)/(\d{4}\-\d{2}\-\d{2}\-[a-zA-Z0-9\-_]+)$ $1?s=$2 [L]
RewriteRule ^(.*/)?staff.php/([a-zA-Z0-9\-_]+) $1staff.php?s=$2 [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule (.*)/$ $1 [L]
</IfModule>
Godaddy run a perfectly good shared hosting service, addressing a large market sector -- users who want an active site (that is with some scripting) but without the cost or complexity of paying for or having the expertise to administer their own Linux VM. This isn't a GoDaddy problem. Its yours.
So first get to understand the environment that you are running under by running a phpinfo script, and make sure it creates the variables that you use. As far as I can see on your example:
Rules 1-3 are 301 redirections to enforce some request naming convention.
Rule 1 redirects /index.php to /
Rule 2 collapses trailing multiple / to a single /
Rule 3 rewrites GET requests for *.php to *.php/
Rules 4-6 map public URIs to internal ones
Rule 4 rewrites /*/yyyy-mm-dd-word to *?s=yyyy-mm-dd-word (note no QSA)
Rule 5 seems to be attempting to rewrite /*/staff.php/word to /*/staff.php?s=word but the syntax is wrong for this.
Rule 6 replaces any trailing / by .php on redirection
Rule 7 strips any trailing '/' unless the uri is a directory with an index.php (I assume that you are assuming a DirectoryIndex index.php (is this the case for GoDaddy?)
This is all hopelessly confused. Are you hiding or exposing the .php extension? Because Rule 3,5 and 6 are inconsistent. And rule 5 would seem more logical as
RewriteRule ^(.*?)/staff.php/([a-zA-Z0-9\-_]+) $1/staff.php?s=$2 [L]
Go back to the drawing board and work out what you are trying to do with your htaccess rules; what you want your public URI grammar to be; how your scripts are laid out; what redirects you want to pass back to the client browser and which you want Apache to handle as internal rewrites and what extra conditions are needed to prevent looping and misfiring. Make sure this makes sense and then debug them by building up your .htaccess file one rule at a time and using test requests to exercise each rule in turn to validate what its doing.
Trying adding the following at the start of your htaccess file. I had the same problem getting rewrites to work on GoDaddy which worked everywhere else:
Options -Multiviews

htaccess command to prevent master site access via subdirectory?

I have hosting setup with a master domain (mapped to the web root) and then a number of addon domains (each with their own folder within the web root). At the moment you can visit www.masterdomain.com/addondomainsubdir and reach the same page as you would if you visited www.addondomain.com (which maps to /public_html/addondomainsubdir). I want to prevent this so if you visit www.masterdomain.com/addondomainsubdir then it will do a 301 redirect to www.addondomain.com. The new addondomain.com site is a single page site so it does not have to map any additional pages.
Adding rules to the htaccess file in the web root does notaffect anything as the subdir exists which is wierd as i thought the htaccess command should work even if there is a matching subdir (i've tried the following which works when there's no matching subdir):
RewriteRule ^addondomainsubdir?$ http://www.addondomain.com [NC,R=301,L]
Logically given it's reaching this directory I figure i need to add a command within the htaccess file in the addondomainsubdir directory however nothing appears to have any effect (i've got various other rules setup and they work fine).
I would be massively grateful if anyone explain the best way to rectify this?
Thanks so much for your help,
Dave
I know this is an old post, but it has never been successfully answered. So for all of you finding this via search, this should do what the OP is asking.
Add this line to your .htaccess file:
redirect permanent /addondomainsubdir/ http://www.addondomain.com
Try these rules in your .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for http
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^([^/]+)/?$ http://www.$1.com/ [R=301,L]
# for https
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^([^/]+)/?$ https://www.$1.com/ [R=301,L]
Instead of putting a rule in your main .htaccess, I would make make a .htaccess for each add-on domain, putting each one in the respective subdirectory.
RewriteEngine on
RewriteCond %{HTTP_HOST} masterdomain\.com$ [NC]
RewriteRule ^addondomainsubdir(.*)$ http://www.addondomain.com/$1 [R=301,L]

Resources