• Resolved visnevskis

    (@visnevskis)


    Hi,
    I found your plugin while trying to get wordpress site movable across servers/directories.
    When I installed it the site broke down, but I made it run by changing config:

    define(‘WP_HOME’, ‘http://’ . $_SERVER[‘HTTP_HOST’] . ‘/subdir/site’);
    define(‘WP_SITEURL’, ‘http://’ . $_SERVER[‘HTTP_HOST’] . ‘/subdir/site’);
    define(‘WP_CONTENT_URL’, ‘/wp-content’);
    define(‘DOMAIN_CURRENT_SITE’, $_SERVER[‘HTTP_HOST’]);

    But it seems to do nothing for now. Could it be usable for subdirectory installs?

    Thanks.

    http://wordpress.org/extend/plugins/root-relative-urls/

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter visnevskis

    (@visnevskis)

    * by nothing I mean – when changing site directory.

    Thread Starter visnevskis

    (@visnevskis)

    Nah, nevermind. Made my own plugin to make sort of relative paths. Will post once it gets reviewed.

    Plugin Author MarcusPope

    (@marcuspope)

    Hmm, interesting I’d love to see your approach. I’m not quite sure what it would take to support a subdirectory installation, but it should be feasible with perhaps another php constant. I’ll add this as a todo item for future versions.

    Thanks!
    -Marcus

    Thread Starter visnevskis

    (@visnevskis)

    Not the most elegant solution perhaps, but very simple:
    http://wordpress.org/extend/plugins/relative-links-for-content/

    Take home part of links, replace by a “shortcode” and generate correct links on loading. Content now can be edited in a local sub-directory and uploaded with nothing to change.

    Marcus,

    I stumbled across your plugin, when I found my testing servers domain “http://localServerName/wordpress/….” on my production server.

    So I was looking for a way to use root relative URLs in my image links.

    Your original approach for the wp-config.php rendered my installation useless. It seems I had the same difficulties as visneskis.

    The standard setup installed my WP into http://localServerName//wordpress so I changed your lines to this:

    define(‘WP_HOME’, ‘http://’ . $_SERVER[‘SERVER_NAME’]. ‘/wordpress’);
    define(‘WP_SITEURL’, ‘http://’ . $_SERVER[‘SERVER_NAME’]. ‘/wordpress’);
    define(‘WP_CONTENT_URL’, ‘/wordpress/wp-content’);
    define(‘DOMAIN_CURRENT_SITE’, $_SERVER[‘SERVER_NAME’]);

    btw I found a note to use the “more reliable” (cite) $_SERVER[‘SERVER_NAME’] instead of $_SERVER[‘HTTP_HOST’]

    The point is, these changes allowed me to insert an image with an root relative path even before I activated your plugin.

    So please don’t take me wrong, but what is your plugin for, if the requirement of a root relative path is met with the above lines ….?

    regards
    Heinz

    Thread Starter visnevskis

    (@visnevskis)

    Are you sure the links are root relative? Are the post links and images displayed Ok when you move WP to another server or directory?

    @visnevskis

    They are root relative in the html-view of the editor
    They are root relative in the exported xml file
    They are root relative in the sql db

    So yes, I’m pretty sure the are root relative 😉

    I don’t know, what would happen if I move to an other diretory (guess it won’t work) but it definitely works if I move to another domain i. e. htttp://development => http://www.production.com

    Thread Starter visnevskis

    (@visnevskis)

    So do I get it right –
    all you did is adding to conf –

    define(‘WP_HOME’, ‘http://’ . $_SERVER[‘SERVER_NAME’]. ‘/wordpress’);
    define(‘WP_SITEURL’, ‘http://’ . $_SERVER[‘SERVER_NAME’]. ‘/wordpress’);
    define(‘WP_CONTENT_URL’, ‘/wordpress/wp-content’);
    define(‘DOMAIN_CURRENT_SITE’, $_SERVER[‘SERVER_NAME’]);

    – and links became relative?

    Yes, that is what I did … I just ckecked it on my production server and it worked that way.

    The only plugins I have activatet on the production site are
    NextGEN Gallery and
    OrangeBox

    If I add an image with the Hochladen/Einfügen (upload/insert) button just above the texteditor window it opens a window where I could drop an file into (from Computer), select from URL or Mediathek or NextGen Gallery.

    I choose Mediathek, select an image click on “Anzeigen” (Show) and I already get the root relative URL presented e. g. “/wordpress/wp-content/uploads/2012/08/xxx.jpg”

    That’s it for me. Sorry that I can’t offer a more complicated way 😉

    You said all links … so far I needed it only for image links.

    I just found out, that it doesn’t work on inserted links.

    To insert a root relative Link, I have to activate the plugin … and so I just found out, what the use of the plugin is.

    Thank you visnevskis 🙂

    Also if you insert a new Category or Page from Dashboard => Design => Menus you only get a root relative link if the plugin is activated.

    Plugin Author MarcusPope

    (@marcuspope)

    @wp_hela – That is interesting, it sounds like maybe there was an update with the image insert logic. Before my plugin and even with the wp-config hacks it used to put in full urls. I’ll double check this with my plugin disabled.

    I use HTTP_HOST instead of SERVER_NAME because if you access the site from localhost instead of the actual server’s name, I need to know ‘localhost’ was where you accessed it from so I can strip it out of certain places where WP will inject it. IIRC SERVER_NAME is system defined so if user browses a HOST redirected site I wouldn’t be able to match the SERVER_NAME with the host value used in the browser. But I will certainly look into this as it could be one of the problems causing infinite 301 redirects for a very small group of users.

    As for what purpose my plugin serves, it’s very faceted. My plugin should make all of your links root relative in your content – links, pages, menus, images (media items really.) It allows you to access your host from multiple domains/ip addresses/host maps. So you can access your development site from http://127.0.0.1/ and from http://computername/ and from http://www.productionsimulatedhost.com/. Without my plugin you could do this with the wp-config hack recommended by the WP core team, but you end up with those literal host names in your database content.

    And you cannot use that method to login to the admin portal because it will auto redirect you to the value used in the url defined under Settings > General (at least this was the case in wp3.1 when I wrote the plugin.) The end result is being able to test admin features from devices like the iPhone where host redirects are not configurable without rooting the phone.

    My plugin also re-injects dynamic absolute urls for RSS feeds because two popular feed readers google reader and feedburner have bugs in their parsing logic, and they will report root relative links as relative to their root and not your site. They are bugs that neither company will fix and virtually no other piece of software since 1998 has this problem, but alas reality is what it is.

    Basically my plugin is designed to make it easy to test multiple wordpress installations that all share the same database, or host multiple sites from the same database, and be able to migrate that content from development to staging to production on a repeated basis without doing any dangerous transformations to the sql exports.

    But thanks for tipping me off to the root relative images, and I’ll see what I can do with SERVER_NAME versus HTTP_HOST – hopefully it will provide a solution for those with 301 redirects.

    Thanks,
    Marcus

    Plugin Author MarcusPope

    (@marcuspope)

    @visnevskis – were you able to use your subdirectory installation with that configuration? You may also want to try http_host instead of server_name just to see.

    Let me know if that does work for you (with my plugin enabled) and I’ll update the readme.

    Thanks,
    Marcus

    Marcus, I’m back …

    I spent hours on a “Error 310: ERR_TOO_MANY_REDIRECTS” problem, just to find out, it’s all your fault *gg*

    No, to be honest I like your plugin. The only problem ist, that it makes the <!–nextpage–> pagination also root relative … which is something, my host server really, really does NOT like.

    Ist there a way to switch it off for <!–nextpage–>?

    It works with <!–more–> btw

    regards
    Heinz

    Plugin Author MarcusPope

    (@marcuspope)

    @wp_hela, I’ve actually been trying to hunt down this problem since day 1, and only yesterday have I even been able to reproduce it. It’s not just <– nextpage –> that has the issue, but permalinks for custom post types also throw infinite redirects under certain conditions.

    After finally being able to reproduce it on a customer’s site, we’ve identified at least one fix, which is to go into Admin > Settings > Permalinks, and click Save Changes twice in a row (let page refresh after each click of course.)

    Would you mind trying that out for me to see if it fixes your problem? If it doesn’t, do you mind reporting your permalink strucutre as well?

    To stop the infinite loop just add this code to the root relative url plugin at the bottom after the other add_filter calls:

    add_filter('redirect_canonical', function($redirect, $requested) {
       if (MP_WP_Root_Relative_URLS::proper_root_relative_url($redirect) == MP_WP_Root_Relative_URLS::proper_root_relative_url($requested) ) {
          return false;
       }
       return true;
    }, 10, 2);

    It doesn’t actually solve the problem of wordpress not finding the post and redirecting, but it does stop the inifinite redirects. Updating permalinks twice should solve the problem of not finding the posts however.

    Thanks for bearing with me on this.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Plugin: Root Relative URLs] Subdirectory install?’ is closed to new replies.