Know the rules The Paceline Forum Builder's Spotlight


Go Back   The Paceline Forum > General Discussion

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2017, 05:36 PM
Keith A's Avatar
Keith A Keith A is offline
Administrator
 
Join Date: Dec 2003
Location: Space Coast of FL
Posts: 18,101
Any .htaccess experts out there?

I'm struggling a bit getting my .htaccess settings correct and was wondering if there are any .htaccess experts out there. If so, please contact me.

TIA.
__________________
My '96 CSi & compact CSi
The Paceline . . . Enjoy the ride.
Reply With Quote
  #2  
Old 04-24-2017, 06:49 PM
rkhatibi rkhatibi is offline
Senior Member
 
Join Date: Aug 2014
Location: SF, CA
Posts: 266
I can help, but generally suggest adding config to the Apache vhost config rather than using .htaccess. However if .htaccess is what the hosting company supports, that's fine too. Assuming you're trying to redirect http to https, this is one of the simpler ways to do it.

Code:
<IfModule mod_rewrite.c>
  RewriteEngine On 
  RewriteCond %{SERVER_PORT} 80 
  RewriteRule ^(.*)$ https://forums.thepaceline.net/$1 [R,L]
</IfModule>
I like to wrap this in a module check for mod_rewrite in case it's not turned on. If you add this and the site loads, but you do not get redirected to the https site, it's possible the rewrite module has not been enabled. Someone will need to run

Code:
sudo a2enmod rewrite
sudo service apache2 restart
You can verify the redirect using curl from an OSX, Linux, or Windows 10 machine with Linux tools installed. Should look like the following with a 301 code and the correct https location.

Code:
[rkhatibi ]$ curl -I http://twitter.com
HTTP/1.1 301 Moved Permanently
content-length: 0
date: Mon, 24 Apr 2017 23:45:12 GMT
location: https://twitter.com/

[rkhatibi ]$ curl -I http://twitter.com/search
HTTP/1.1 301 Moved Permanently
content-length: 0
date: Mon, 24 Apr 2017 23:45:14 GMT
location: https://twitter.com/search
Reply With Quote
  #3  
Old 04-24-2017, 07:14 PM
Keith A's Avatar
Keith A Keith A is offline
Administrator
 
Join Date: Dec 2003
Location: Space Coast of FL
Posts: 18,101
Thanks so much for the reply!!! The other thing that I want to do is redirect www.thepacelinet.net to forums.thepaceline.net.

Here is my current .htaccess...

Quote:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.thepaceline\.net
RewriteRule (.*) http://forums\.thepaceline\.net/$1 [R=301,L]
And here's what our host company suggested I use...

Quote:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.thepaceline.net/$1 [R,L]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.thepaceline\.net
RewriteRule (.*) https://forums\.thepaceline\.net/$1 [R=301,L]
order allow,deny
When I use the latter, I run into a problem of when I type in forums.thepaceline.net, it tries to redirect this to https://forums.thepaceline.net/forums. I don't know where the extra "forums" is being appended.

For now, I went back to the original .htaccess settings and you can access the site from both http and https. When I used the new .httaccess file, I can see that not many users can get to the forum.

Do you see something wrong in the modified .htaccess file that would cause this problem?

I'll have to check our host company regarding the Apache host config modifications.
__________________
My '96 CSi & compact CSi
The Paceline . . . Enjoy the ride.
Reply With Quote
  #4  
Old 04-24-2017, 07:35 PM
rkhatibi rkhatibi is offline
Senior Member
 
Join Date: Aug 2014
Location: SF, CA
Posts: 266
It's redirecting so server config should be good. Just wanted to give you options on testing it. Often hard to tell what's going on within the server.

I think what we have is two separate sets of redirects.

RewriteCond %{SERVER_PORT} 80 is grabbing any http traffic that comes in including http://forums. Then redirecting it to https://www, then it hits a redirect from http(s)://www to http://forums and finally https://. Maybe.

I'd try the following to send traffic directly to https://forums and hopefully skip any other actions.

Code:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://forums.thepaceline.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.thepaceline\.net
RewriteRule (.*) https://forums.thepaceline.net/$1 [R=301,L]
order allow,deny
Reply With Quote
  #5  
Old 04-24-2017, 07:50 PM
Keith A's Avatar
Keith A Keith A is offline
Administrator
 
Join Date: Dec 2003
Location: Space Coast of FL
Posts: 18,101
rkhatibi -- Thanks again for the reply and information. I'll give this a try in the morning. I especially appreciate the tip on how to test this...that will make things a lot easier. I assume I can test this on the Linux server this site is running on...correct?
__________________
My '96 CSi & compact CSi
The Paceline . . . Enjoy the ride.
Reply With Quote
  #6  
Old 04-25-2017, 10:46 AM
rkhatibi rkhatibi is offline
Senior Member
 
Join Date: Aug 2014
Location: SF, CA
Posts: 266
Yep you can run those tests from the server itself.

If you have console access to the server and can change the Apache config there are a few other things you can look at.

This should list the vhost files. You can look directly at them to see if there are other rewrite rules in effect
Code:
ls -la /etc/apache2/sites-enabled/
less /etc/apache2/site-enabled/www.thepaceline.net.conf
# or whatever the file name is
You can also add debug logging to your .htaccess which might provide clues to the source of the extra /forums/.

Code:
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 3
Further docs here, https://httpd.apache.org/docs/2.2/en...tml#rewritelog and while log level supports 0-9 anything above 2 can start adversely affecting the server. I'd try 3 for debugging, but keep an eye on CPU for a minute or two just in case. Should be fine on the server you have.
Reply With Quote
  #7  
Old 04-25-2017, 11:00 AM
Keith A's Avatar
Keith A Keith A is offline
Administrator
 
Join Date: Dec 2003
Location: Space Coast of FL
Posts: 18,101
I do have access to a console on the server and can view the files in the directory you listed. There are a number of *.conf files in there, but I'm not sure what to check for in these files for the rewrites. I haven't played around with these files before, so I'm a newbie
__________________
My '96 CSi & compact CSi
The Paceline . . . Enjoy the ride.
Reply With Quote
  #8  
Old 04-25-2017, 12:18 PM
rkhatibi rkhatibi is offline
Senior Member
 
Join Date: Aug 2014
Location: SF, CA
Posts: 266
hahah, alright you're getting a class in Linux webserver administration 101.

in /etc/apache2/sites-enabled/ there are probably 4-5 files. I'd suspect default.conf, www.conf, and forums.conf or something similar. The default is installed as part of the Apache package IIRC. Anything else should be added by you, vbulletian, or the hosting provider. I prefer naming the config files after the site they represent, forums.thepaceline.net.conf etc, but it's by no means universal.

I'd look at each one to see what you have there may be a mix of general config and Apache vhosts. The top of the file will probably look like this.

Code:
/etc/apache2/sites-enabled/99_some_file.conf

<VirtualHost *:80>
  ServerName somesite.example.com
  DocumentRoot /var/www/sitesite

   #bunch of other stuff
What you'll need to map out is ServerName and ServerAlias per file. And the sort the load order of those file. Apache parses them the way they are sorted on disk when you use ls -la. This means that is www.thepaceline.com is in two files, the one that's named a.conf will take precedence over the one named b.conf. Once you've mapped out the names and the file order, you can look for duplicates. I'd recommend removing the ducplicates to start.

The next step is to look for rewrite rules within the Apache vhost files and map the behavior of the rewrite rules out per ServerName or ServerAlias. I suspect there is a www.thepaceline.net config that has rewrite rules already in it and this is causing the problems you're seeing.

There's a fair amount of information there and happy to explain more if you have questions.

Lastly after you understand what's going on, I'd recommend simplifying the config. Maybe remove any www specific config, I believe forums is the only site on the machine, and make things look roughly like the following

Code:
keith@yourserver ~ $ cd /etc/apache2/sites-enabled/
keith@yourserver /etc/apache2/sites-enabled $ ls -l
total 12
-rw-r--r-- 1 root root 2824 Mar 13 18:40 00_default.conf
-rw-r--r-- 1 root root  821 Apr 10 14:10  90_forums.conf
-rw-r--r-- 1 root root  821 Apr 10 14:10  99_redirect.conf
keith@yourserver /etc/apache2/sites-enabled $ cat 90_forums.conf
<VirtualHost *:443>

  ServerName forums.thepaceline.net
  ServerAlias  www.thepaceline.net

  # Force all requests to https://forums.thepaceline.net
  RewriteEngine on
  RewriteCond %{HTTP_HOST}   ^www\.thepaceline\.net$ [NC]
  RewriteCond %{HTTP_HOST}   !^$
  RewriteRule ^/(.*)         https://forums.thepaceline.net/$1 [L,R=301]
  
  # etc etc docroot, ssl, logging and so forth

keith@yourserver /etc/apache2/sites-enabled $ cat 99_redirect.conf
<VirtualHost *:80>

  ServerName forums.thepaceline.net
  ServerAlias  www.thepaceline.net

  # /var/empty should work, you're serving no files
  DocumentRoot /var/empty
  ErrorLog /var/log/apache2/redirector-error.log
  TransferLog /var/log/apache2/redirector-access.log
  LogLevel error

  # *any* traffic to this vhost gets redirected
  # basically the same as the other stuff, just a one liner
  RewriteEngine On
  RewriteRule ^(.*) https://forums.thepaceline.net%{REQUEST_URI} [QSA,R=301,NC,L]
You would have the port 443 (https) config that is the site and the port 80 (http) config is simply a redirector to the other vhost.

Feel free to DM or email me config files too if that makes it easier. Always hard when you don't now exactly what you're looking at.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:49 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.