URL Rewrite issue when site_url is different from home_url
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.
- 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.
- 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
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.
Thank you, Ravi.
Thanks Ravi, got the same issue here. Where did you change the references to solve 1.?
Guys - I got the same issue here. Where I need to change anything to fix issue 1 ?
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!
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
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).
I mean, wordpress.org/latest.zip unzips into /wordpress/... so any theme should support site different from home
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.
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.
@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).
@raytara I would love to see what your steps were for solving #2 as I'm running into the same issues.
@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.
@raytara Thank you, Ravi.
I'm having the same problem (WP 3.5, Roots 6.1.0). Glad I found this post. Thanks Ravi, worked like a charm.
closed by @damianregan's fixes pulled in with #688
Thanks @damianregan !
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 thank you so much!
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!