sage icon indicating copy to clipboard operation
sage copied to clipboard

URL Rewrite issue when site_url is different from home_url

Open zillionart opened this issue 14 years ago • 20 comments

First up, thanks for such an awesome theme. I hope to contribute to make it a much better theme going forward.

I have installed wordpress (http://www.example.com/wordpress) in a different directory than my home url (http://www.example.com). In this case there are two issues that I faced with the URL re-write functions.

  1. The constants defined in config.php (especially RELATIVE_THEME_PATH and RELATIVE_CONTENT_PATH) were stripping away the /wordpress part that was necessary to define the correct relative path.
  2. The folder that the htaccess.php uses to write into the .htaccess file was also causing the theme to break. It is accessing the root folder while it need to write into the /wordpress folder.

I solved #1 by changing the reference from site_url to home_url and the second I manually copied the .htaccess file to the /wordpress sub-folder.

Did I miss any tricks?

Thanks, Ravi

zillionart avatar Aug 25 '12 03:08 zillionart

Unfortunately we don't really support that setup. There's some references to this in older issues, but there was a bug within WordPress that prevented us from fixing it. I'm pretty sure we could fix it now if we wanted to. Just hasn't been a priority since we don't use that setup.

Thanks for hacking around with the source though. We always encourage that. If you do come across a fix that also supports what we have now, let us know.

As for the .htaccess issue, I assume it's something in lib/htaccess.php. Any reference to filepaths in there uses home_path() so you'll have to work around that.

swalkinshaw avatar Aug 25 '12 03:08 swalkinshaw

Thank you, Ravi.

2b3pro avatar Sep 03 '12 03:09 2b3pro

Thanks Ravi, got the same issue here. Where did you change the references to solve 1.?

timoburmeister avatar Sep 16 '12 09:09 timoburmeister

Guys - I got the same issue here. Where I need to change anything to fix issue 1 ?

monkviper avatar Sep 22 '12 07:09 monkviper

I made the modifications in config.php that is located inside the /lib folder. You can do a search for the constant names that I have defined above (in my version of the code they are on lines #38 and #40). Hope this helps. Cheers!

zillionart avatar Sep 24 '12 20:09 zillionart

Hey raytara,

thank you! I didn't get it...what was the new code, you've inserted?

the standard code looks like that: $get_theme_name = explode('/themes/', get_template_directory()); define('GOOGLE_ANALYTICS_ID', ''); // UA-XXXXX-Y define('POST_EXCERPT_LENGTH', 40); define('WP_BASE', wp_base_dir()); define('THEME_NAME', next($get_theme_name)); define('RELATIVE_PLUGIN_PATH', str_replace(site_url() . '/', '', plugins_url())); define('FULL_RELATIVE_PLUGIN_PATH', WP_BASE . '/' . RELATIVE_PLUGIN_PATH); define('RELATIVE_CONTENT_PATH', str_replace(site_url() . '/', '', content_url())); define('THEME_PATH', RELATIVE_CONTENT_PATH . '/themes/' . THEME_NAME);

so where did you stripped the /wordpress ? my subfolder ist called /cms/

thanks in advance!

bye Timo

timoburmeister avatar Sep 25 '12 12:09 timoburmeister

It's a shame this theme does not support this standard Wordpress functionality.

For many developers, setting home different from site is the standard. This allows to support several script packages on a single domain's public_html, e.g. /wordpress /vanilla /phpbb all in separate folders under the /public_html/ , which makes management and installation much easier... also allows to have a fallback index file which can send traffic to any of the script packs or to a placeholder page.

It won't prevent me from working with this theme, but it does go against my best practices (a. to set wordpress public root, b. to hack core files).

PlayGod avatar Oct 21 '12 14:10 PlayGod

I mean, wordpress.org/latest.zip unzips into /wordpress/... so any theme should support site different from home

PlayGod avatar Oct 21 '12 15:10 PlayGod

roots ain't a standard wordpress theme. no core files are hacked.

just disable the URL rewrites or use a different theme. this bug will eventually be fixed.

retlehs avatar Oct 21 '12 16:10 retlehs

Well, I meant theme's core files... I do understand, I am just lazy, complaining because it will cause me additional work. On another note, will this theme work with a child theme? I am ALL about using this theme for a current project that needs bootstrap and LESS... so I will put up with the current state of affairs. Thanks for your work thus far.

PlayGod avatar Oct 21 '12 21:10 PlayGod

@timoburmeister Sorry for the delay in responding to your message. Your config.php file looks slightly different from my version. Maybe there was an upgrade since I last checked. In your case, you need to replace,

          define('RELATIVE_CONTENT_PATH', str_replace(site_url() . '/', '', content_url()));

with

          define('RELATIVE_CONTENT_PATH', str_replace(home_url() . '/', '', content_url()));

Also my original problem #2 was also resolved using the hack pointed out by @swalkinshaw in the htaccess.php.

Let me know if you want the exact steps for solving #2 (I need to retrieve it from my archives).

zillionart avatar Oct 22 '12 11:10 zillionart

@raytara I would love to see what your steps were for solving #2 as I'm running into the same issues.

dlchung avatar Dec 03 '12 18:12 dlchung

@dlchung. I hard-coded the sub-directory structure to line #23 of htaccess.php file (in the lib folder) after the get_home_path call.

For example, if your Wordpress installation is in a directory called "blog" relative to your root folder, then change the path to ".htaccess" as "/blog/.htaccess".

I am sure that you can find some Wordpress function that might return the sub-directory path programmatically but I did this quick hack to get going with Roots.

zillionart avatar Dec 05 '12 11:12 zillionart

@raytara Thank you, Ravi.

dlchung avatar Dec 05 '12 16:12 dlchung

I'm having the same problem (WP 3.5, Roots 6.1.0). Glad I found this post. Thanks Ravi, worked like a charm.

mcallinder avatar Jan 03 '13 10:01 mcallinder

closed by @damianregan's fixes pulled in with #688

retlehs avatar Feb 21 '13 20:02 retlehs

Thanks @damianregan !

Geczy avatar Feb 21 '13 21:02 Geczy

If anyone else is struggling, I had the same problem of my wordpress root being installed in a subfolder. No other approaches I've been reading through have worked for me so... I made the following change in the init/rewrites.php to the roots_add_rewrites function.

function roots_add_rewrites($content) {
  global $wp_rewrite;
  $roots_new_non_wp_rules = array(
    'assets/css/(.*)'      => str_replace('/', '', WP_BASE) . '/' . THEME_PATH . '/assets/css/$1',
    'assets/js/(.*)'       => str_replace('/', '', WP_BASE) . '/' .  THEME_PATH . '/assets/js/$1',
    'assets/img/(.*)'      => str_replace('/', '', WP_BASE) . '/' .  THEME_PATH . '/assets/img/$1',
     'plugins/(.*)'         => str_replace('/', '', WP_BASE) . '/' .  RELATIVE_PLUGIN_PATH . '/$1'
  );
  $wp_rewrite->non_wp_rules = array_merge($wp_rewrite->non_wp_rules, $roots_new_non_wp_rules);
  return $content;
}

Then just reinstall the theme, worked for me.

markstewie avatar Mar 10 '13 06:03 markstewie

@markstewie thank you so much!

n0tlocal avatar Mar 28 '13 03:03 n0tlocal

Is there any update on this as of yet? Is commenting out the line:

add_theme_support('rewrites'); // Enable URL rewrites

An okay practice? What will that do to the site in other ways? Thanks!

findhvacdealer avatar Aug 21 '13 18:08 findhvacdealer