Support » Fixing WordPress » Accessing wp-admin on a different port/url

  • I am setting up a new wordpress site and have apache setup to redirect all admin requests to a different port number on the same server, this port is firewalled and only accessible internally. A quick search online reveals a few people with similar queries who have not got anywhere with the problem.

    My apache site configuration looks something like this and is doing its job as intended:

    <Directory /opt/wp-directory>
            RewriteEngine On
            RewriteBase /
            RewriteRule ^index\.php$ - [L]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . /index.php [L]
    Listen 715
    <VirtualHost *:80>
            RewriteEngine On
            DocumentRoot /opt/wp-directory
            RewriteRule ^/?(wp-login.*|wp-admin.*)$1 [R=301,QSA,L]
            RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)
            RewriteRule .* - [R=405,L]
    <VirtualHost *:715>
            DocumentRoot /opt/wp-directory

    And I have added the following near the bottom of my wp-config.php file:

    switch ($_SERVER['SERVER_PORT']) {
        // Admin site
        case "715":
        // Live site
            define("WP_HOME",''); // trailing slash
            define("WP_SITEURL",''); // no trailing slash

    However it seems that any links created or media uploaded in the admin site (on the alternate port) have the part hard coded in the database so when users visit the site these images wont load and links wont work.

    I suppose I can just do a search and replace in the database but I can’t help but feeling that there must be a better way to do this. Any help that anyone can provide would be greatly appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’d do one of two things.

    1) Add Apache basic-authentication in front of wp-login.php (via wp-admin/.htaccess).

    2) Only allow access to wp-login.php and admin to an internal IP:

    Root-level .htaccess:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
    RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$
    RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$
    RewriteRule ^(.*)$ - [R=403,L]

    Updating this line:

    RewriteCond %{REMOTE_ADDR} !^xxx\.xxx\.xxx\.xxx$

    with your actual IP address.

    Or even simpler:

    <FilesMatch wp-login.php>
    Order Deny, Allow
    Allow from
    Deny from all
    Thread Starter crispybusiness


    Thank you Scriptrunner, I should have mentioned this in my initial post but unfortunately it is not feasible to limit access by IP address as we have a large number of users accessing the site from different IP address some of which will be dynamic. We already have a firewall in place which allows access to port 715 from their IP address.

    I have had more of a look around these forums as I am relatively new to wordpress and am coming to the conclusion that this is not going to be easily possible. If I figure anything out or find a solution I’ll post it here.

    Yes, dynamic IPs will pretty much make that solution impossible. (or incredibly difficult at best)

    I’ve not ever used a separate port for WordPress admin specifically, though it should be possible.

    The only thing I can think of (in regards to your original question) would be to use the WordPress wp_insert_post_data filter hook and remove the port (using a regex) before saving the post to the database.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Accessing wp-admin on a different port/url’ is closed to new replies.