htaccess code file for pretty URLs
Permalink# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /installation_directory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
# -- concrete5 urls end --
Yii, a PHP framework that I use, to achieve the "pretty URL" effect of removing index.php from the URL, recommends the following code:
# -- yii urls start --
<IfModule mod_rewrite.c>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
# -- yii urls end --
Source:http://www.yiiframework.com/doc/guide/1.1/en/topics.url...
I know they are 2 different systems but you don't have to be a genius to realize that both portions of code are doing the same thing.
I want to bring this out because the C5 code recommendation includes the relative path where the C5 site is installed e.g. the "RewriteBase /installation_directory/" part. This means that you have to check/change this code whenever you deploy your C5 site from local to live. I'm guessing that changing this is a common scenario.
So, my question is... is including the subdirectory in the code really necessary? I commented that line months ago and my C5 site is still working fine with no problems that I can see.
If that's not really necessary and the C5 team removes that line, it would be one less thing to take into account when moving a C5 site (from local to live, migrating to a new server, etc)
I tested removing the .htaccess line in a fresh C5 5.6.0.2 and on an old v5.5.x site and it seems to work fine.
The 404 error you get must be related to the DIR_REL option you set. Is that option really needed? I can put my C5 site in a subdirectory in my localhost environment and I don't need to tell C5 in which subdirectory it is... I have yet to test that on a subdirectory in a live server though.
I just tested my site by removing the define('DIR_REL... and removing the line from the .htaccess and my site fails with 404's.
Maybe it depends on the server. I haven't thought about it cuz if it ain't broke, I don't fix it.
If the C5 core team recommends I do something, I generally do it because they've seen a lot more edge cases than I ever will.
localhost/c5_project
And I can move it to a different subdirectory without any modifications (this is, without the "RewriteBase" line) and it works fine:
localhost/web/c5_project
I just find strange having to tell C5 in which sub directory it is. I don't understand it, since it can just use relative paths to its current directory, wherever it is, no matter how deep it is relative to the "root".
I will try later this on a live server.
Edit: I also don't think that DIR_REL is required since it doesn't come by default in the site.php file... at least not in my C5 install.
1) Whenever I set up my localhost for a new website, I need to tell it where the files are so my server is already landing right on the index.php file. The nameservers for a real site just land users on the true root of the site.
2) DIR_REL is not included in the default set up because a normal installation is in the root, not in a sub-directory. If you type DIR_REL into the search box you will find plenty of explanations.
1) I made the tests and the C5 site works fine on different subdirectories both on my localhost and live server environment, without having to specify the subdirectory anywhere.
2) I found a confirmation from the C5 core team that the BASE_URL and DIR_REL are not required anymore since C5 tries to guess them:
http://www.concrete5.org/developers/bugs/5-5-1/base_url-and-dir_rel...
I think this RewriteBase /installation_directory/ might not be necessary for most sites. I would like it if somebody can confirm this. I know it works for me but I'd like to be sure that this is intented behavior and not just that I'm lucky this time. I'd like not to specify the installation directory so I can deploy from local to live without having to change that file.
have you got an .htaccess file in your root?
Log back into your website and untick the 'Remove index.php from URLs' in 'System & Settings' > 'URL's and Redirection' and then save the settings, clear your cache and go back and retick the 'Remove index.php from URLs' and save the settings.
You should find a new .htaccess file created for you.
Let me know when you have done that...
http://www.mysite.com/C5/concrete
I just tested it and if I remove the line you're talking about from my .htaccess file, my pages all 404.
I also add "define('DIR_REL', '/C5');" to my site.php file