Redirect External link backs to https

MAD
MAD
@madc
10 years ago
600 posts
I am trying to work out my htaccess to redirect links from external sites to https and www version

Problem:

People have been posting links to our site leaving off the https and www.
eg. http://punkbandpromotions.com/k-usr-radio
( link should be https://www.punkbandpromotions.com/k-usr-radio )

when people click that link it goes to a not found page
https://www.punkbandpromotions.com/modules/jrCore/router.php?_uri=k-usr-radio

why is it injecting the /modules/jrCore/router.php?_uri=
If that was gone the link would work

this is my htaccess edit

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]



--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion

updated by @madc: 06/05/14 06:25:47AM
michael
@michael
10 years ago
7,715 posts
The routing system is what makes jamroom work.

"Understanding the Routing system"
Understanding the routing system | Jamroom 5

So your going to want to keep that routing link in there.

Not so good at these, I usually just keep playing around til i find something that works, but as a guess.... try:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/modules/jrCore/router.php?_uri=$1 [R=301,L]
MAD
MAD
@madc
10 years ago
600 posts
Thanks @michael .
Nah it doesn't work
i get the url
https://www.punkbandpromotions.com/modules/jrCore/router.php?_uri=modules/jrCore/router.php\
I need to remove the modules/jrCore/router.php?_uri=
That is just adding after it

Wouldn't it need a specific rule?
Like
RewriteCond %{HTTP_HOST} ^punkbandpromotions.com$
RewriteRule ^modules\/jrCore\/router\.php\/?(.*)$ "https\:\/\/www\.punkbandpromtions\.com\/$1" [R=301,L]
( that doesn't work by the way )


--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion

updated by @madc: 04/26/14 04:04:40AM
brian
@brian
10 years ago
10,148 posts
Try this:

RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^punkbandpromotions\.com [NC]
RewriteRule .? https://www.punkbandpromotions.com%{REQUEST_URI} [R=301,L]

Let me know if that works.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
MAD
MAD
@madc
10 years ago
600 posts
Unfortunately @brian that didn't work either.
if you go here
punkbandpromotions.com/k-usr-radio
it shows this as the url with a 404
https://www.punkbandpromotions.com/modules/jrCore/router.php?_uri=k-usr-radio

any other thoughts?
the proper link obviously works. We just want to fix it if people for example forget the www
eg
http://punkbandpromotions.com/k-usr-radio
breaks ( No www )
punkbandpromotions.com/k-usr-radio
breaks ( no www or http or https )
www.punkbandpromotions.com/k-usr-radio
works ( no http or https )
I have left your edit it to show you the results

BTW I have it after the core redirect


# All requests through the router
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)favicon\.ico$ modules/jrCore/img/favicon.ico [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ modules/jrCore/router.php?_uri=$1 [NC,L]
</IfModule>
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^punkbandpromotions\.com [NC]
RewriteRule .? https://www.punkbandpromotions.com%{REQUEST_URI} [R=301,L]



--
~ https://punkbandpromotions.com ~
Check us out for all your Punk/Alternative Music!
Check us out on Facebook:- https://facebook.com/PunkBandPromotion

updated by @madc: 04/27/14 04:17:42AM
brian
@brian
10 years ago
10,148 posts
This is what we use here on jamroom.net to redirect all non-www to www:

# HTTP
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^jamroom\.net [NC]
RewriteRule .? http://www.jamroom.net%{REQUEST_URI} [R=301,L]

# HTTPS
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^jamroom\.net [NC]
RewriteRule .? https://www.jamroom.net%{REQUEST_URI} [R=301,L]

of course change to your domain, but that is working for us.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
michael
@michael
10 years ago
7,715 posts
instead of R=301,L try [NC,L] as that's what the original one is

Original .htaccess file:

# All requests through the front controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ modules/jrCore/router.php?_uri=$1 [NC,L]


So here's a few more guesses from me.
# HTTP
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^jamroom\.net [NC]
RewriteRule .? https://www.jamroom.net%{REQUEST_URI} [NC,L]

# HTTPS
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} ^jamroom\.net [NC]
RewriteRule .? https://www.jamroom.net%{REQUEST_URI} [NC,L]
brian
@brian
10 years ago
10,148 posts
The 301 tells the visitor the URL has changed permanently, which is what you want.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
michael
@michael
10 years ago
7,715 posts
What about this. Leave the standard jamroom .htaccess redirect code in place, as is. Then add a couple of rules BEFORE it to catch any of the wanted issues:

# catch the non www. version and redirect
RewriteCond %{HTTP_HOST} ^punkbandpromotions\.com$ [NC]
RewriteRule ^(.*)$ https://www.punkbandpromotions.com/$1 [L,R=301]


# All requests through the front controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ modules/jrCore/router.php?_uri=$1 [NC,L]
brian
@brian
10 years ago
10,148 posts
Oh yeah - that's what you want. Those rules need to be placed above the main RewriteRule section.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags