CodeIgniter .htaccess for my file structure - php

I was handed down a project from another developer (who's not available any more and I cannot ask him for a solution) where he'd kept multiple codeignitor projects in a folder and called each of them through their respective index files.
The file structure - /var/www/html/{folder}/mobile_index.php
The mobile_index.php references a folder 'mobile' which resides in the same folder as mobile_index.php.
So the URL that I call is - "xx.xx.xx.xx/{folder}/mobile_index.html". This page opens fine but when I click on any link (e.g. user) within the page, this redirects to "xx.xx.xx.xx/user"
Now this page is blank and my error log says there's no page user in /var/www/html/user. But when i manually convert the link to "xx.xx.xx.xx/{folder}/mobile_index.php/user" this works and opens up the page. I think the folder is missing the .htaccess file but I have no clue what to include in that file, can anyone help me get the links working again?
This is what I have so far -
RewriteEngine on
RewriteCond $1 !^(mobile_index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /{folder}/mobile_index.php/$1 [L]

Options +FollowSymLinks
RewriteEngine On
#RewriteBase / #on server, uncomment this line by removing hash'#'
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* mobile_index.php?/$0 [PT,L,QSA]

Related

HTML: ZIP file download from server issue

I'm sorry about my tittle. I'm not sure how I can categorize this question.Please do edit if necessary-Thanks
Here is the issue I'm having:
http://domain.com is my main server- in this main server I'm listing all of the downloadable files I have from another server which is http://myfilehost.com.
on http://domain.com I list my files like so:
download myfile document
download all myfile
The first link is working perfectly fine but when it comes to the zip file I always get the ff error which is really weird:
Here is the htaccess of http://myfilehost.com which I think is the default of wp as its also a wp website not sure if this is hosted on hostgator/bluehost:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And o I think this is also worth mentioning:
When I try to go to http://myfilehost.com first and wait for it to load then add the directory /downloads/myfile.zip to the URL its actually working perfectly and downloading myfile.zip..
Thank you Everyone for your kindness of helping me and giving me a response

Redirect all access from a folder to a PHP file

I want to do a task like this.
I have a folder /doc/ with many documents files inside. When an user trying to access this folder's content, I need to do some verification, so I need to redirect that access to a download.php file in root folder and pass the actual REQUEST_URI to PHP file. I try this in htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/doc.*$ [NC]
RewriteRule ^(.*)$ http://example.com/download.php?r=%{REQUEST_URI} [L,R=301]
But I got ERR_TOO_MANY_REDIRECTS error with the redirected url is: download.php?r=/download.php, which in this case is not what I want (download.php?r=/doc/abc/xyz.pdf is the correct one)
Could someone explain for me about what I did wrong? Thank you very much.
Your rewritecond line is incorrect and it will continue looping forever. You'll need to add a File check so it doesn't use the rewrite condition every time. So it will only use it when it's pointing to a file that doesn't exist
add the following lines
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^doc\/(.*)\.html$ download.php?r=$1 [L,R=301]
with the url http://example.com/doc/file.html
it will redirect the user to download.php?r=file if you wanted to capture the file extension change the last line to
RewriteRule ^doc\/(.*)$ download.php?r=$1 [L,R=301]

.htaccess spits our full URL rewritten URL on folder name

I have the following .htaccess:
RewriteEngine On
RewriteBase /sandbox/
RewriteRule ^(assets)($|/) - [L]
RewriteRule ^(.*)$ lib/script/bootstrap.php?route=$1.php [NC,L,QSA]
What I am doing is redirecting all requests (except for my assets - img, css, js) to my bootstrap script, which will handle the request via the route parameter, which includes the URL request.
This works fine in most cases, except for when I have a call such as:
http://www.example.com/sandbox/admin, where admin is a folder that exists in my directory, amongst other folders. This folder contains various pages that are accessible, aswell as an index.php file that my bootstrap.php routing will redirect requests from the above URL to it, by default.
My problem is that when I attempt to hit the page: http://www.example.com/sandbox/admin, my htaccess (as far as I know) is rewriting the visible URL to http://www.example.com/sandbox/admin/?route=admin.php, which is not as pretty. I believe it's because there's some conflict going on with the fact that the above URL is a valid URL pointing to my /admin/ folder, but I would like my .htaccess to ignore this and send this aswell to my bootstrap.php (line 4 of my .htaccess). What am I doing wrong?
Here is the requests coming in my browser:
UPDATE:
Strangely, http://www.example.com/sandbox/admin/ works fine, but not http://www.example.com/sandbox/admin (notice the trailing slash).
If you have real folders you need to use a condition to ignore real files and folders. All other requests will get routed to your bootstrap file. (If I understand your issue correctly.)
RewriteEngine On
RewriteBase /sandbox/
RewriteRule ^(assets)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ lib/script/bootstrap.php?route=$1.php [NC,L,QSA]

.htaccess is reloading some files twice

My website is a custom made PHP website. I recently made it SEO friendly by copying the .htaccess file from wordpress and modify it a little. The problem is that some pages are realoaded twice especialy pages that have more than 1 backslash like download/something/ . I have noticed this when tracking pageviews one pageviews is counted as twice and i've done a lot of research regarding this and the pageviews are working good it's a very simple function that inserts a new row each time you view a page.
Things to keep in mind:
My website is inside some folders 'https://localhost/simbyone/sim/index.php'.
I don't want to use any GET variables i will have my variables from the URL string
I want .htaccess to look for existing directories located inside 'https://localhost/simbyone/sim/' and if it doesn't find any open index.php with all the strings attached something like 'localhost/simbyone/sim/blabla/' but inside index.php
everything works exactly as i said above the only thing that doesn't do right is that it double loads some pages
this is my .htaccess file:
RewriteEngine On
RewriteBase /simbyone/sim/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /simbyone/sim/index.php [L]
Thanks in advance to anyone that will help me.
Place the .htaccess inside your base folder (in your case, simbyone/sim).
Just put this in the file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php
This will rewrite and request that is not an existing file or folder to the index.php file.
There you can use $_SERVER['REQUEST_URI'] to evalute the request (keep in mind that the prefix "/simbyone/sim/" will be present there.

.htaccess specified url with base file

I have a directory site and its sub-folder and files in it.
It also contain a .htacess and below is the code
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?cc=$1
so my below url will is effective and working good.
http://localhost/site/sweetinc
And below code in index.php below
<?php
if (isset($_GET['cc']) and !empty($_GET['cc'])) {
echo $_GET['cc'];
} else {
die("Sorry wrong code");
}
?>
And this is working good.
Now, i want to access or display all files as normally
http://localhost/site/sweetinc/home.php
http://localhost/site/sweetinc/test.php
home.php and test.php are located in site directory. And if it redirects to other sub-folders then it should
be visible like
http://localhost/site/sweetinc/sub-folder1/test3.php
Is this possible, as I am working seperating a group using seperate directory using .htaccess and considering all files in site directory as base files
The trick here (if I understand your question correctly) is that you don't want the rewrite rule to be in effect when you're trying to reach a file that actually exists, right?
In that case, just before your RewriteRule, add these lines:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
That way, the rewriterule only takes effect when the url (/site/sweetinc for example) does not really exist on the server. If it does (/site/sweetinc/home.php) the rewriterule is skipped and the file is shown.
(-f checks if the filename exists, -d checks if the directory exists, so /home/sweetinc/somedir/ should work too)
Update based on updated question
You need two separate rules for this. First of all, if the /sweetinc/ directory in the url is used, refer them to the /site/ folder:
RewriteRule ^sweetinc/(.*)$ /$1 [L]
Then, if the file does not actually exist, let the index.php handle it:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?cc=$1 [L]
Some examples:
I have the following files in my files subdomain:
/index.php (which has the same content as yours does, so it reads out ?cc=
/circle3.PNG
/the .htaccess with the above rules
http://files.litso.com/sweetinc/hello shows the index.php that echoes "hello"
http://files.litso.com/sweetinc/circle3.PNG shows the actual file in /
(note, I don't have a /sweetinc/ directory, it's all faked)

Categories