I spent several hours today researching this and I can’t seem to find a definitive answer whether this is possible. I use Apache and I have Grav installed in a subfolder of webroot (/public_html/grav). I can access the Grav pages fine by going to www.mysite.com/grav/mypage. However, I would like to access the Grav pages by going to www.mysite.com/mypage.
Installing Grav into the webroot directly is not an option unfortunately due to a picky client who doesn’t want to mix his non-CMS based HTML files with the Grav files. He also doesn’t want to do a redirect from /mypage to /grav/mypage, but rather an internal rewrite that is invisible to the user.
I tried doing a simple rewrite rule in the htaccess file located in webroot, but I get Grav 404 errors that way. My rewrite rule looks like this: RewriteRule ^mypage/?$ /grav/index.php [NC,L]. I imagine Grav can’t figure out what page I’m trying to access, because the URL it gets doesn’t include the directory in which it’s installed.
I also played around with the setup.php file and tried to adapt the multisite setup for m y purpose, but I couldn’t get it working that way either.
Thanks, but that gave me an internal server error. Are you sure that’s correct? Don’t I have to reference /grav/index.php somewhere to make sure Grav gets called?
@Gabe I’ve got this PR in place https://github.com/getgrav/grav/pull/896 it’s meant to work on a domain/subfolder -> domain level, but should also work in your case. Give it a try.
So the rewrite rules I posted are correct…just need to change the system.yaml file. @flaviocopes mine works already without setting the system.yaml file. I was trying to get it to hide the subdomain in the url bar but didn’t have any luck.
@paulmassendari: not sure I can change the dns target directory due to the host being used. Moving Grav a folder higher would put it in webroot, which I’m trying to avoid.
@jmonroe: sorry to be a noob, but what changes do I have to make to system.yaml to get your rewrite rules to work? Looking through all of the settings there, it’s not obvious to me.
Oh ok, I didn’t realize you were referring to that. I was running the stable version of Grav before, so now I’m upgrading to the RC and making those PR changes manually. Thanks for your help!
No problem. All I did was add my htaccess file and it worked. Looks like they added that to the github released version to make it easier to do what you’re doing. Let me know if it works or not.
I may have celebrated too early. The frontend does work, but trying to log into the admin backend (I have the admin plugin installed) gives me an Invalid Security Token error. It’s almost like the admin plugin needs to be modified to use the custom_base_url_absolute as well, but I wouldn’t know where to do that or if that is really the problem. Any ideas or do any of you encounter this too? My htaccess file looks like this now:
So just to recap: if I comment out custom_base_url_absolute, the admin backend works fine at /grav/admin, but the frontend gives me a Grav 404 if I go to /mycmshome. Having custom_base_url_absolute set, the frontend works fine, but the admin backend gives me the Invalid Security Token error.