I have my dev site running in a sub-directory and I do have RewriteBase configured in the .htaccess to point to that sub-directory. However, links within site pages that go to things like "/some/thing.html" end up not working because they go to localhost/some/thing.html instead of localhost/backdrop/some/thing.html.

Is this the expected behavior? 

Most helpful answers

I have a use case that sounds somewhat similar where there is a main domain and backdrop is just a portion of it running in a subdirectory. What we did was set the vhost to a parent directory, created the subdirectory for backdrop within which we have the default .htaccess, core, etc. Everything seems to work just fine. We did not modify base_url.

In a custom module we needed to use 

$path = backdrop_get_path('module', 'custom_module');

and to reference it in some places we needed to use

$image_url = base_path() . $path . '/images/desired_image.png';

 

 

It's a very long time since I did development like that - most of my development is in Lando so I get a different base URL for each site.

Two thoughts come to mind:

  1. Have you set the base URL for the site in settings.php? That may help in defining the site root.
  2. Are you actually trying to link to an HTML page within your site root? It might be that you'll actually need a specific rule for that page within your .htaccess

Comments

It's a very long time since I did development like that - most of my development is in Lando so I get a different base URL for each site.

Two thoughts come to mind:

  1. Have you set the base URL for the site in settings.php? That may help in defining the site root.
  2. Are you actually trying to link to an HTML page within your site root? It might be that you'll actually need a specific rule for that page within your .htaccess

@yorkshirepudding -

Thank you for your thoughts on this. 

  1. I had not set the base URL for the site, but tried it after seeing your post. It does not fix the issue, unfortunately.
  2. There are a great many such links to URL aliases in the site. 
  3. It also happens with inline images. And if I embed them in the dev site, then I get an extra "backdrop/" in the path and it doesn't work in the real site. 

It sounds like the RewriteBase and/or $base_url settings don't actually help this type of situation. Is their purpose only to send requests to the proper index.php?

Hopefully someone else with a bit more knowledge in the intricate workings here can help as I've reached the end of my ideas for things to try and don't have any way to test locally.

Sorry I can't be of any more help.

@leeksoup Have you tried "some/thing.html", essentially dropping the leading / that is taking you to the root of your domain which is localhost

A better solution may be to modify your vhost to use the backdrop directory as the root of the domain.

In some places, yes, that works. But since that would make it a relative path, it doesn't work for most cases. Thanks for the suggestion of the vhost ... I will try that out. :)

I have a use case that sounds somewhat similar where there is a main domain and backdrop is just a portion of it running in a subdirectory. What we did was set the vhost to a parent directory, created the subdirectory for backdrop within which we have the default .htaccess, core, etc. Everything seems to work just fine. We did not modify base_url.

In a custom module we needed to use 

$path = backdrop_get_path('module', 'custom_module');

and to reference it in some places we needed to use

$image_url = base_path() . $path . '/images/desired_image.png';