Changing Site URL on Apache

Hi,

Really impressed with Grav so far, though a couple of issues when I pushed the site to a host running Apache.

Moved setup to: /public_html/[site], and want now to remove the [site] from the URL and map it to the root. I’ve followed the docs (https://learn.getgrav.org/advanced/change-site-url), and tinkered with .htaccess but with no luck; always ends with a 403 when visiting the route, so I’ve just set up a redirect on cpanel for now as a rough fix.

Has anyone done exactly this and can provide a howto?

Cheers in advance.

Hi! It is a long time since I have used cPanel, but how it worked before was to change it inside cPanel.

When you add the domain you want to use you have to add a document root. You can probably change the domain that you already have also.

Hi, wouldn’t the Solution be to put the files in public_html? Or do you have a reason to place them in a separate directory?

I think cPanel puts every public content inside public_html. That is why it has to be organized with folders.

But as I read the cPanel docs I found that every domain and sub-domain will have an option to select any folder in public_html to be root.

So there should not be any problem.

For the sake of organisation, having folders under public_html is useful: I have a few subdomains and another add-on. I’ve put the site in a folder there too, surely that should be fine?

I’m not able to change the root of the main domain to the subfolder for some reason, but it should be possible from cPanel as procrates mentioned.

Ultimately, annoyingly, the grav url includes the subfolder name, and I’d like to remove that:

Currently: http://www.site.co/subfolder/
Ideally: http://www.site.co/

Yes, I’ve got a .co domain. I’ll live with that.

Cheers.

You can check your .htaccess that the Part RewriteBase / is used.

Not really sure what you meant here. This is what I see. When you already have a domain you can modify it with the same option.

As of the .htaccess, the original file should work when your sever points the domain to the Grav root.

I’ve just tried this with the main domain and apparently I “cannot park my main domain”. Apologies if I’m being a tit.

What should I do here if I’m changing my main domain? The only one listed here currently is my addon, a separate domain.

Thought this was the same issue … but apparently not:

I end up with some kind of redirect loop. Frustrating.

Strange that you cannot modify the main domain.

And yes it should work to edit the .htaccess to use a sub-folder.

## Begin RewriteBase
# If you are getting 500 or 404 errors on subpages, you may have to uncomment the RewriteBase entry
# You should change the '/' to your appropriate subfolder. For example if you have
# your Grav install at the root of your site '/' should work, else it might be something
# along the lines of: RewriteBase /<your_sub_folder>
##

# RewriteBase /

Did you uncomment # RewriteBase / and add your sub-folder?

Right, being systematic, it worked, but not as I expected.

Added redirects (manually, not via cPanel) in the domain root .htaccess

RewriteEngine on
RewriteCond %{REQUEST_URI} !(.)folder
RewriteRule ^(.
)$ folder/$1 [L]

Removed the mod_rewrite content from the grav .htaccess.

Added the following to system.yaml:

custom_base_url: 'http://site.co
absolute_urls: true
session:
path: /

Seemed to do the trick, with a few cache refreshes, as was unable to log in at first.

Then had to remove all internal links that included the folder path. Painful, but it’s only a small site currently.

Only thing I’ve yet to sort is deal with the lack of www in the redirect, but that should be easy enough to find.

One thing is broken, which is the path to the main page logo, which is the same as all other working image paths, so that has me slightly baffled:

src="{{ url(‘theme://images/main_logo.png’) }}"

Thanks for pitching in folks. Hope this helps someone else out there.

No wonder the paths broke.

If there is one tip I should give you it should be: Start over (backup your user folder, make your domain folder root to Grav even if you have to change the server block, install Grav again and replace user folder with your folder.)

The bigger your site become the harder it is to change it if you do some hacky solution now. Trust me… Done that.

I’m not sure what you mean. Are you saying to start again to test the fix?

I’ve managed to get it to do what I’m after (apart from the www part), documented it and backed it up, so what does that achieve?

If what you suggest is worth doing, convince me, and I’ll do it.

Yes, you did manage to get it working, but those redirects will confuse Grav and make your life harder when adding links, images and more.

Try this: https://encode.host/knowledgebase/4119/How-to-Install-GRAV-via-Softaculous-in-cPanel.html
or something similar by searching google.