Forum Moderators: phranque

Message Too Old, No Replies

rewrite rule for redirecting port number

via an .htaccess or httpd.cinf file?

         

Kydd

8:43 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



We're trying to create a redirection where any URL's that were formerly ourdomain.com:8000 now simply redirect to ourdomain.com.

We were running an FTP server via Tux that required port 80 but we switched to vsftpd.

jdMorgan

8:49 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Kydd,

Weclome to WebmasterWorld!

Use RewriteCond [httpd.apache.org] %{SERVER_PORT} to test for NOT port 80, and if so, 301-redirect all requests to your canonical URL using [R=301,L] on the RewriteRule.

Jim

Kydd

10:01 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Thanks for the quick response!

Any chance at another idea using an .htaccess file or inserting something in the httpd.conf file? I'm just a little confused about how to actually write something based on what you suggested...

jdMorgan

11:58 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We'll be happy to help you get your code working, but we can't write code on request here. Demand far outstrips the free time of our members and volunteer staff.

For some useful references and more information on our policies, see our forum charter [webmasterworld.com]. At the very least, reading the mod_rewrite and regular-expressions reference material and taking a shot at coding a solution will get you conversant with the terminology and techniques.

The only difference between your application and the simple redirection examples in the documentation is what I posted above -- you'll need to test the port number and only do the redirect if it is not port 80.

If you don't want to try to do it yourself, then you could post in our commercial exchange [webmasterworld.com] forum for bids.

Jim

Kydd

2:01 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



OK here's my first take on it:

RewriteEngine on
RewriteCond %{SERVER_PORT}!^80$
RewriteRule ^/(.*) [ourdomain.com...] [L,R]

Now I've tried this in the httpd.conf file, restarted Apache, as well as trying this in an .htaccess file and it does not appear to work. We did have 'Listen 80' so I simply added 'Listen 8000' and with the redirect rule it works so thanks for your suggestions.

jdMorgan

4:08 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest that you use [R=301,L] to generate a Moved-Permanently redirect. We've had big problems with 302 redirect handling in the search engines recently, as evidenced by the hundreds (thousands?) of posts in WebmasterWorld search engine forums threads.

Other than that, your code looks fine.

Jim