2

This is my first post to StackOverflow, so please bear with me......

I'm trying to redirect www.example.com to https://example.com. I've looked at quite a few solutions on StackOverflow and other forum sites, but I can't seem to get anything to work. Here are a few of the other StackOverflow pages I've looked at:

Generic htaccess redirect www to non-www

apache redirect from non www to www

Redirect Non-WWW to www

My SSL cert lists both example.com and www.example.com. Here is the code in my apache2.conf file that I've been trying to add the redirect:

<Directory /home/tim/examplepath>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ sort-url.php?rt=$1
</Directory>

<VirtualHost XXX.XXX.XX.XXX:12345>
    ServerName example.com
    Redirect / https://example.com/ 
</VirtualHost>

<VirtualHost XXX.XXX.XX.XXX:80>
   ServerName example.com
   Redirect / https://example.com/
</VirtualHost>

<VirtualHost XXX.XXX.XX.XXX:123>
   ServerName example.com
   DocumentRoot /home/tim/examplepath/
   SSLEngine on
   SSLCertificateFile /etc/ssl/certs/example.com.crt
   SSLCertificateKeyFile /etc/ssl/certs/example.key
   SSLCertificateChainFile /etc/ssl/certs/sf_bundle.crt
</VirtualHost>

I would like everything to redirect to https://example.com/sort-url.php?rt=$1 where I can then determine which page to show based on the variable $1.

Can someone please tell what I need to do? ServerAlias in the and the 301 redirect inside of the haven't worked for me.

Thank you in advance!

Tim

4

2 回答 2

1

欢迎来到 SO!

如果您希望一切都结束,example.com您可以将其设为您的_default_站点。我认为你可以这样做:

<VirtualHost _default_:*>
   Redirect permanent / https://example.com
</VirtualHost>

<VirtualHost XXX.XXX.XX.XXX:123>
   ServerName example.com
   DocumentRoot /home/tim/examplepath/
   SSLEngine on
   SSLCertificateFile /etc/ssl/certs/example.com.crt
   SSLCertificateKeyFile /etc/ssl/certs/example.key
   SSLCertificateChainFile /etc/ssl/certs/sf_bundle.crt

   RewriteEngine On
   RewriteBase /
   # Check is HTTPS is used
   RewriteCond %{HTTPS} =off
   RewriteRule ^(.*)$ https://example.com/sort-url.php?rt=$1 [R=301,L]

   # If we have not specified a file to access, redirect to sort-url.php
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ sort-url.php?rt=$1
</VirtualHost>

我必须承认这是未经测试的,我有点不确定您是否需要一个VirtualHost重定向到 SSL 的非 SSL 连接。

编辑
更改,以便默认主机只转发以https://example.com确保使用正确的主机名。

于 2013-10-09T08:28:01.863 回答
0

我必须在我的 Rackspace 帐户的 DNS 记录中添加一个 CNAME。CNAME 是“www.highschoolclothing.com”。

不过谢谢大家的帮助!

于 2013-10-11T00:29:04.647 回答