Welcome Guest, Not a member yet? Register   Sign In
Quick help with .htaccess needed
#1

[eluser]snarkq[/eluser]
Hey guys, thank you for reading and understand I have been hacking away at this for many hours and look forward to learning from your assistance!

Problem outline:
1) I have been working on my CI website for a few months under a subdirectory with the structure www.site.com/beta/index.php?/controller/function etc..
2) I am trying to setup .htaccess files to allow www.site.com/controller/function etc..
3) I would like to keep all of my CI files in the subdirectory so that I can just change the htaccess to a different subdirectory, essentially changing the site in one stroke and having it invisible to the users

Problems I am experiencing:
1) Going to www.site.com does NOT work, but www.site.com/controller DOES work
2) After any redirect()'s the site changes to www.site.com/beta
3) echo site_url and echo base_url are all www.site.com/beta
4) Forms do not work - they try to access www.site.com/beta/form. If i change it to www.site.com/form (for logging out as an example) it works.

Any idea what is going on? This mismatch is hard to pinpoint. I am familiar with RegEx but unfamiliar with .htaccess.

The following are my two .htaccess files. The first is in the web root, the second is in the subdirectory.

www .htaccess:
Code:
#Options
Options -Multiviews
Options +FollowSymLinks

#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /beta

#Removes access to CodeIgniter system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

RewriteRule ^(.*)$ index.php?/$1 [L]

/beta/ .htaccess:
Code:
# Options
Options -Multiviews
Options +FollowSymLinks

#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /

#Removes access to CodeIgniter system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

RewriteRule ^(.*)$ index.php?/$1 [L]

Anything jump out? Thank you for your help! I have been at this for many many hours I promise!
#2

[eluser]CroNiX[/eluser]
I believe rewritebase needs a slash before AND after the subdirectory.

These lines are unnecessary and aren't actually doing anything if you are using CI 2+
Code:
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

Also, this isn't doing anything:
Code:
RewriteCond $1 !^(index\.php|images|robots\.txt|css)

Because you already have:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
which does the same thing except it allows all REAL existing files/directories instead of only the named ones
#3

[eluser]snarkq[/eluser]
Thanks for your help CroNiX,

I removed those lines, and added the trailing slash, but nothing seems to have changed (Which you hinted at by saying they weren't actually doing anything)

If i go to www.site.com I get the standard apache file browser which shows all of my folders in the base directory, including beta/.

If I click on that it still takes me to www.site.com/beta (which works), but I still have the base_url, and site_url, displaying www.site.com/beta/. In addition, I still have the problem where form_open tries to access www.site.com/beta/form which does NOT work, but it does work if you force it (with standard html form syntax) to www.site.com/form. I would like to maintain portability of the site so this is not an option for me

Some additional settings I have in config.php if it helps elucidate the problem:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';


Any help resolving these problems is most appreciated! Thank you in advance.
#4

[eluser]snarkq[/eluser]
I would like to add that changing $config['base_url'] to "http://www.site.com/beta/" fixes everything, but the URL still displays http://www.site.com/beta/controller/function/ etc. which I am trying to avoid.
#5

[eluser]CroNiX[/eluser]
It would be best to set up a virtual server so you don't need a subdirectory in the url in the first place. Then when you switch to a production server you won't have to change anything either as both development and production sites would have similar environments with the application in the webroot directory.
#6

[eluser]snarkq[/eluser]
Thanks CroNiX,

I am currently producing the website on WAMP, is this what you are referring to? I believe that you have suggested the best solution. I was concerned with copying over the website updates while it is live, this is why I was thinking simply changing the .htaccess subdirectory might be the best solution to keep client images of the website during an update "atomic".

However, perhaps simply accepting some short downtime might be acceptable. Thanks for your input
#7

[eluser]CroNiX[/eluser]
I don't personally use wamp, but this might be helpful: http://www.trailheadinteractive.com/crea...windows_xp. It talks about windows xp but the HOSTS file/directory is the same on more modern versions.

Using a new virtual server for each of your projects is the only way to develop, imo. Less time mucking around as it should be exactly the same on your dev as the live server. Same .htaccess, same files, etc.

#8

[eluser]snarkq[/eluser]
CroNiX,

That is very useful! Thank you for the information.




Theme © iAndrew 2016 - Forum software by © MyBB