CodeIgniter htaccess subfolder problem - apache

I want a second website in my domain inside the folder test
www.mydomian.com/test
Apache server running on linux.
But when I load it in my navigator styles, images, helpers can't be found.
My htaccess is like this:
RewriteEngine On
RewriteBase /test
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /test/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Thank you in advance
I have tried what you said, placing the htaccess file you gave me in the test folder and the other one in the root directory, it didn't work.
Other options?

Try adding a .htaccess file into your test folder instead.
I use this .htaccess content:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
In the folder test I would place another .htaccess, with almost the same content:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test/index.php?/$1 [L]

Related

htacess RewriteRule http://domain/folder/(any searchstring) to redirect to http://domain/folder/index.php?option=$1

I am trying to create a rewrite rule in my Apache .htaccess file and the goal is:
http://domain/folder/(any search string) to redirect to http://domain/folder/index.php?option=$1
example:
http://domain/folder/covid to redirect to http://domain/folder/index.php?option=covid
I got this setup in htacess in http://domain/folder, but somehow it's not working:
RewriteEngine On
RewriteRule ^([^/folder]+)/([^/]+)$ http://domain/folder/index.php?option=$1 [L]
The website is hosted on http://domain/folder
Can someone help me on this?
You may try this .htaccess inside folder/:
RewriteEngine On
RewriteRule ^index\.html?$ index.php [L,NC]
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ index.php?option=$0 [L,QSA]
You could have your htaccess file like as follows. Please keep your htaccess file along side with your folder(named folder) and NOT inside folder.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?option=$1 [L]
OR in case your htaccess is present inside folder folder then try following.
RewriteEngine ON
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?option=$1 [L]

My Apache rewrite code (provided) in .htaccess works, but also re-writes favicon.ico. How fix?

I have always used this simple code to have all requests use one index.php file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? index.php [L]
However, I have just found that it's also re-writing the favicon.ico file.
My understanding is that the code above should rewrite only index.php and no other file or directory. Am I wrong? How would I fix this?
Just add an exception for it in your rules.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/favicon.ico [NC]
RewriteRule .? index.php [L]

Redirect to a specific subfolder using htaccess

Here's my folder structure:
website.com
main
sub1
sub2
I would like to be able to access the subfolder sub1 via the URL website.com/sub1, which I managed to do so by adding the following in my .htaccess under website/ :
RewriteCond %{REQUEST_URI} /sub1/(.*)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ main/sub1/index.php?view=$1 [QSA,L]
My problem is that although the index.php is accessed, it is accessed all the time, even for the .js and .css files. So I tried to add the following rule before (although I though I excluded the files via my !-f condition before):
RewriteCond %{REQUEST_URI} /sub1/(.*)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ main/sub1/$1 [L,QSA]
But as you can guess, no luck, no actual files ever go into that second block even when I delete the other one.
Try:
RewriteCond %{REQUEST_URI} ^/sub1/(.*)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/main/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /main/$1 [L]
then your old rules:
RewriteCond %{REQUEST_URI} /sub1/(.*)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ main/sub1/index.php?view=$1 [QSA,L]

Apache htaccess rule for url shortening

I'm trying to create something
short.com/ASWi7 -> short.com/index.php?h=ASWi7
so I tried using this code on my htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /index.php?hash=$1 [L]
but the website loses the css and everything...i organized my site in folder etc...
so how can i exclude all the folders or cetain files to be part of that rule?
Try the following:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /index.php?hash=$1 [L]
!-f checks for existing files
!-d checks for existing directories
Hope that helps.

Add directory in the middle of a URL with hataccess

My current .htacces file looks like this:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
What I am trying to accomplish (as well as the above) is to change a url such as http://domain.com/pages/pagename to something like http://domain.com/index.php/pages/view/pagename.
Keeping in mind that I still require urls without the /page/ part such as http://domain.com/search to go to http://domain.com/index.php/search. I am working with CodeIgniter.
What I have come up with so far is:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
RewriteCond %{REQUEST_URI} ^/pages/(.*)
RewriteRule ^(.*)$ ./index.php/pages/index/$1 [L,QSA]
But it isn't working.
Try this one:
RewriteEngine on
# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# /pages/ specific rule
RewriteRule ^pages/(.*)$ index.php/pages/index/$1 [L]
# everything else
RewriteRule ^(.*)$ index.php/$1 [L]
The above assumes that http://domain.com/pages/ is not a real folder.
RewriteRule ^pages/(.*) /index.php/pages/index/$1