htaccess code file for pretty URLs
Permalink
Hi, to enable "pretty URLs", C5 recommends the following code in the .htaccess file:
# -- 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)
# -- 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)
Thanks for reporting your case.
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 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 think the DIR_REL is used by a number of blocks and they fail if that isn't defined. I can't remember which ones off the top of my head.
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.
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.
Just a thought but are you setting up your localhost to land on the subdirectory?
Hmm, I haven't set up my localhost to do anything special. I install C5 in, say:
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.
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.
Two things...
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) 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.
Hi, two things:
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.
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.
All I can confirm is that I have a site that's in a sub-directory off the root. It works fine if I leave out the DIR_REL definition in site.php but it fails if I comment out the "RewriteBase /installation Directory/". When I say 'fail', I mean I can always land on my homepage but as soon as I navigate off the homepage I get 404's.
I am having problems with this similar problem. I am needing desperate help and hope one of you can help me!
What version of concrete5 are you using?
have you got an .htaccess file in your root?
have you got an .htaccess file in your root?
I just installed it this week, so the most recent one. I did but when i started trying to play around with it, the whole file got deleted. Concrete5 Support said she couldn't handle this problem and directed me to A2Hosting support who has also had no luck and submitted my ticket to their gurus. I am very new to C5 and the backend of websites, really lost right now.
Delete the .htaccess file...
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...
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...
I have already deleted the .htcaccess file, I still get a 403 forbidden message popping up. Resulting in me still not being able to login to my site. Any other suggestions?
I have had success by uploading an empty .htaccess file up to the server and then logging in by going to http://your_website.com/index.php/login....
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