Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Automatically create 301 redirects
New Posts  All Forums:Forum Nav:

Automatically create 301 redirects

post #1 of 6
Thread Starter 
Hey guys,

I'm looking for a way to automatically create 301 redirects on my site. I have 1000+ pages so I don't exactly want to do this by hand.

The site is www.ftwpc.com. I'm going to be making some changes to the site setup and have the store at store.ftwpc.com and main content at ftwpc.com.

All of the pages should internally link to each other somehow so the site could be crawled. The other thought was to use the sitemap.

The help is appreciated.
Mr. Windy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9650 Asus Maximus II Formula EVGA GTX 460 8GB OCZ 800Mhz 
Hard DriveOSMonitorPower
2x300 V-Raptor, 2x1TB WD, 2xSegate 320GB Fedora 14 2x Samsung 245BW Corsair 750TX; APC BR1500 
Case
Soldam Windy Altium FC 700 
  hide details  
Reply
Mr. Windy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9650 Asus Maximus II Formula EVGA GTX 460 8GB OCZ 800Mhz 
Hard DriveOSMonitorPower
2x300 V-Raptor, 2x1TB WD, 2xSegate 320GB Fedora 14 2x Samsung 245BW Corsair 750TX; APC BR1500 
Case
Soldam Windy Altium FC 700 
  hide details  
Reply
post #2 of 6
Create a script that goes through the old pages, and sets something similar to the following on the old files:
http://www.webconfs.com/how-to-redirect-a-webpage.php

(Assuming that the new address(es) are similar except the new store.ftwpc.com address) Make the new address to dynamically get created based on the old path.

This is also assuming that not many pages are going to be re-named or moved, just relocated.....



I would write something to do this, but i don't have the time right now to write the batch file....
 
Tragbar
(14 items)
 
 
CPUMotherboardGraphicsRAM
Ryzen 1800X Asus Crosshair VI Hero Nvidia Geforce Titan X F4-3600C15D-16GTZ 
Hard DriveHard DriveHard DriveHard Drive
Combined: 6.13 TB of space Samsung SSD 960 EVO 500GB Crucial_CT1050MX300SSD1 M4-CT128M4SSD2 
CoolingCoolingCoolingCooling
EK-Supremacy EVO White Edition PrimoChill PrimoFlex Advanced LRT EK-RES X4 250 (R2.0) Reservoir EK-CoolStream XE 360 
CoolingCoolingCoolingOS
EK-Vardar F4-120ER (2200rpm)  EK-Ekoolant EVO Liquid Coolant EK-XTOP Revo D5 PWM Pump Windows 10 Pro 
MonitorKeyboardPowerCase
Asus VG278H Ducky YOTG Keyboard Corsair AX1200 Corsair Obsidian 800D 
MouseAudioAudioAudio
Logitech G700s Schiit Gungnir Multibit Schiit Mjolnir 2 Schiit LISST 
Audio
Audeze LCD 2 - pre fazor 
CPUMotherboardGraphicsRAM
intel i7 4770K ASRock Z87E-ITX Nvidia Geforce GTX Titan X GSkill F3-2400C10D-16GTX R 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro 512GB Silverstone 12.7mm Slot Load Blu-Ray Burner Noctua NH-L12 Windows 8 Pro 
MonitorCaseAudioAudio
LG PA75U Slim LED Projector Silverstone SG08 Schiit Bifrost Schiit Asgard 2 
AudioOther
AKG Q701 Headphones Pelican 1510 Green Case  
  hide details  
Reply
 
Tragbar
(14 items)
 
 
CPUMotherboardGraphicsRAM
Ryzen 1800X Asus Crosshair VI Hero Nvidia Geforce Titan X F4-3600C15D-16GTZ 
Hard DriveHard DriveHard DriveHard Drive
Combined: 6.13 TB of space Samsung SSD 960 EVO 500GB Crucial_CT1050MX300SSD1 M4-CT128M4SSD2 
CoolingCoolingCoolingCooling
EK-Supremacy EVO White Edition PrimoChill PrimoFlex Advanced LRT EK-RES X4 250 (R2.0) Reservoir EK-CoolStream XE 360 
CoolingCoolingCoolingOS
EK-Vardar F4-120ER (2200rpm)  EK-Ekoolant EVO Liquid Coolant EK-XTOP Revo D5 PWM Pump Windows 10 Pro 
MonitorKeyboardPowerCase
Asus VG278H Ducky YOTG Keyboard Corsair AX1200 Corsair Obsidian 800D 
MouseAudioAudioAudio
Logitech G700s Schiit Gungnir Multibit Schiit Mjolnir 2 Schiit LISST 
Audio
Audeze LCD 2 - pre fazor 
CPUMotherboardGraphicsRAM
intel i7 4770K ASRock Z87E-ITX Nvidia Geforce GTX Titan X GSkill F3-2400C10D-16GTX R 
Hard DriveOptical DriveCoolingOS
Samsung 840 Pro 512GB Silverstone 12.7mm Slot Load Blu-Ray Burner Noctua NH-L12 Windows 8 Pro 
MonitorCaseAudioAudio
LG PA75U Slim LED Projector Silverstone SG08 Schiit Bifrost Schiit Asgard 2 
AudioOther
AKG Q701 Headphones Pelican 1510 Green Case  
  hide details  
Reply
post #3 of 6
Use mod_rewrite on every page you want to redirect so it redirects to a PHP script or something, passing it the URL of the original page, then in the PHP script redirect using HTTP 301 using the URL to the original page to redirect to the correct page. There's probably another server mod that does this and doesn't require a PHP script in the middle.
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
post #4 of 6
this can all be done in Apache's config (eg .htaccess files). There's no point doing it in code.
post #5 of 6
Thread Starter 
Quote:
Originally Posted by Plan9 View Post

this can all be done in Apache's config (eg .htaccess files). There's no point doing it in code.

Can you elaborate on how to create the redirects with the .htaccess?
Mr. Windy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9650 Asus Maximus II Formula EVGA GTX 460 8GB OCZ 800Mhz 
Hard DriveOSMonitorPower
2x300 V-Raptor, 2x1TB WD, 2xSegate 320GB Fedora 14 2x Samsung 245BW Corsair 750TX; APC BR1500 
Case
Soldam Windy Altium FC 700 
  hide details  
Reply
Mr. Windy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9650 Asus Maximus II Formula EVGA GTX 460 8GB OCZ 800Mhz 
Hard DriveOSMonitorPower
2x300 V-Raptor, 2x1TB WD, 2xSegate 320GB Fedora 14 2x Samsung 245BW Corsair 750TX; APC BR1500 
Case
Soldam Windy Altium FC 700 
  hide details  
Reply
post #6 of 6
Quote:
Originally Posted by mortimersnerd View Post

Can you elaborate on how to create the redirects with the .htaccess?

Coma touched on this with the mod_rewrite comment, but you can do it all in apache:
http://www.isitebuild.com/301-redirect.htm

Basically the bit you want from the link above is this:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://store.domain.com/$1 [R=301,L]
Which should redirect anything from www.domain.com to store.domain.com and leave domain.com (without www) intact.

If you want to redirect www.domain.com/store then you cannot use %{HTTP_HOST} as you're matching the URL - so I'm not sure how you'd want to format that. But it's all very flexible as it's just regex matching.

So just dump that into a .htaccess file (please note the prefixed full stop) and save the file in the docs home for the site which you want to redirect. (or alternatively put in the vhost config for extra security - just bare in mind that doing so would require bouncing Apache where as .htaccess files do not).
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Automatically create 301 redirects