Jump to content

How to forward URLs but keep everything after the domain.

pbx2

Hiya, I'm using Apache (and not willing to change to nginx) and have started moving stuff over to a new domain.
I want to keep the paths while still routing traffic to the new domain.

Example:

www.test.com/i/gjs12 -> www.test2.com/i/gjs12

This needs to be automatic and cannot be done on a per page basis.

 

--- Purple Prime ---
i7 8700k + Hyper 212 Evo | MSI Z370 Gaming Pro CarbonG-Skill Trident Z 3000Mhz RGB 16GB | Gigabyte Aorus GTX 1080ti

Crucial MX500 500GB | WD Black 2TB | Corsair RM850i | Fractal Design Define R4LG 27UD68-P | Logitech G502 + G910 | Windows 10 Pro

--- Proteus Server ---

AyyMD Ryzen 5 3600 | Asrock B450m Pro-4 | Crucial Ballistix Sport LT 32 GB (2 x 16 GB) | Sapphire RX570 NITRO+ 8GB

Crucial MX500 1TB + Samsung Spinpoint F4 2TB + Seagate 1TB 2.5" + 5TB iDrive  | Windows 10 Pro (Temporary)


--- Camera Stuff ---
Canon EOS 77D | Canon EF-S 18-55 f/4-5.6 IS STM | Canon EF-S 55-250 f/4-5.6 IS STM | Canon EF 50mm f/1.8 STM 
Zoom H5 + XY-5
Phone - Oneplus 6T

Link to comment
Share on other sites

Link to post
Share on other sites

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 Fractal Design Meshify C Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to comment
Share on other sites

Link to post
Share on other sites

You can use mod_rewrite

 

If two sites are on different server:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ http://www.new_domain.tld/$1 76 [R=301]

Served by the same Apache:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} old_domain\.tld$ [NC]
RewriteRule ^(.*)$ http://www.new_domain.tld/$1 76 [R=301,L]

 

or if you want both www and without www

 

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
  RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>

or you can put this in the root .htaccess

 

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, BobVonBob said:

I did this and now it's half working
It forwards to the new domain but also doesn't work correctly

It does this:
test.com/i/test -> test2.comi/test


Edit: Never mind this was due to me not setting up PermanantRedirect properly for SSL

--- Purple Prime ---
i7 8700k + Hyper 212 Evo | MSI Z370 Gaming Pro CarbonG-Skill Trident Z 3000Mhz RGB 16GB | Gigabyte Aorus GTX 1080ti

Crucial MX500 500GB | WD Black 2TB | Corsair RM850i | Fractal Design Define R4LG 27UD68-P | Logitech G502 + G910 | Windows 10 Pro

--- Proteus Server ---

AyyMD Ryzen 5 3600 | Asrock B450m Pro-4 | Crucial Ballistix Sport LT 32 GB (2 x 16 GB) | Sapphire RX570 NITRO+ 8GB

Crucial MX500 1TB + Samsung Spinpoint F4 2TB + Seagate 1TB 2.5" + 5TB iDrive  | Windows 10 Pro (Temporary)


--- Camera Stuff ---
Canon EOS 77D | Canon EF-S 18-55 f/4-5.6 IS STM | Canon EF-S 55-250 f/4-5.6 IS STM | Canon EF 50mm f/1.8 STM 
Zoom H5 + XY-5
Phone - Oneplus 6T

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×