remove index.php codeigniter in localhost/folder/my_codeigniter/ - php

i have try a few solution from any source, but still cannot remove index.php if my project in other folder like : http://localhost/project/my_codeigniter, all .htaaccess and configuration work fine if my project in http://localhost/my_codeigniter.
hope you can help me, thanks!

You can create a .htaccess file on your project root folder. File content like this;
RewriteEngine on
RewriteCond $1 !^(index\.php|assets)
RewriteRule ^(.*)$ /your-project/index.php/$1 [L]

Related

htaccess RewriteRule using slash as get params: can't access other files in the folder

I have a simple user system in my site. The URL works like this: /profile/user?id=user_id
I wanted to do something like /profile/user/user_id instead, and I found the following code to use in htaccess.
RewriteRule ^user/(.*)$ user.php?id=$1 [L]
The code does work as intended, but after doing that I found out that I can't access any other file inside of the profile directory besides the index file. All of them return a 404 error.
There's a couple more of important pages in there, so I would need to access them. I can't access user.php without an ID either, but that's not my main concern, even though I would also like to access it if possible.
I'm not really used to use RewriteRule, so I'm not really sure what's going on here. What can I do?
EDIT: I was asked to give more info, here we go.
The profile folder full route is /en/profile
Structure of the profile folder:
profile/settings.php (directory index)
profile/user.php
profile/change_avatar.php
profile/change_avatar_upload.php
profile/change_email.php
profile/change_password.php
profile/custom_utgen_characters.php
profile/custom_utgen_character_editor.php
profile/reset_password.php
Other lines in the htaccess file:
DirectoryIndex settings.php
htaccess file in the root folder of the website:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
This is all the relevant option I could get, I hope it helps.
I tested your rewrite rule and directory structure and had no problems to access files in the profile directory. Can you provide more information like the complete .htaccess file and the directory structure laying under profile?
EDIT: The .htaccess in your profile folder overwrites the .htaccess in your root folder. To prevent this, you have to add the line
RewriteOptions inherit
to the .htaccess file in the profile folder.

Cakephp 3.0: rewrite .htaccess rule to allow new folder access?

I'm using cakephp 3.0 and I'm facing a problem. I upload my site on server on root level, where I place some demos which I can use for other purpose. Now issue is that when I access my site with domain name then it is working fine. But if I give any folder name which is placed on root level which is not the part of my site and is indiviual part of site. Then it is not accessible.
Below is my folder structure of root level
There a single folder named gallery is a demo. How can I allow this folder to access like this http://hostname.com/gallery or any other new folder.
My .htaccess file code is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Please help me on this issue which is more appreciable.
Thanks in advance.
Just move your "gallery" folder under "webroot".
Try this it's worked for me.
create the .htaccess file in "gallary" folder with following content.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
and try with URL http://server_name.com/gallary
You have access for that folder and files.
Thanks.

Removing index.php from Code Igniter

I've done a search for my question but have yet seen one similar to mine.
I have a newly installed CI on my server, for security reason I have shifted the "application" and "system" folder outside of public_html and into a folder called "app". I tried a lot of methods that the forums were using but none seem to help.
Below is my folder structure, would like to know what to type for the .htaccess and where does this .htaccess go to?
/
app (system and application folder for CI resides here)
public_html (index.php - the one which defines ENVIRONMENT, styles, other htmls and my current .htaccess resides here)
My current .htaccess looks like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
Please help! Thank you for your time!
EDIT
Currently my url is something like this
xxx.xxx.xxx.xxx/~app/index.php/user/check/id
(it's on a shared hosting but not linked to domain yet and hence the ip address and partition in the url.)
I want to achieve something like
xxx.xxx.xxx.xxx/~app/user/check/id
and it should work when I link up my domain. (e.g. www.mydomain.com/user/check/id)
Alright, I think I've solved the problem.
This has most probably got to do with the 'unique' url that I have. I assume if it is a normal domain name it shouldn't have so much problems.
My url > xxx.xxx.xxx.xxx/~app/index.php/user/check/id
My directory structure remains the same >
/app (application and system directories goes here)
/public_html (index.php and .htaccess goes here)
.htaccess code as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~app/ << NOTE the addition
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
In config.php, set
$config['base_url'] = 'http://xxx.xxx.xxx.xxx/~app/';
$config['index_page'] = '';
That's all!

Failed to load resource: CodeIgniter (works fine locally)

I've just transferred a project of mine to the web and I have a file called "circlecrop.php" that's located in the root directory of where all the CodeIgniter files are. This php script basicall just makes any image with circlecrop.php?path=img cropped to a circle, very simple and it works fine locally.
This works perfectly fine locally.
I'm getting the following error:
Failed to load resource: the server responded with a status of 403 (Forbidden)
I can't access circlecrop.php directly even though I've got it set to 777, I haven't anything set within my routes in CodeIgniter I'm not sure it's needed?
Complete htaccess file
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|circlecrop\.php|images|js|profile_pictures|fonts|stylesheets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I've done some searching and can't seem to find anything, my only thought is that I need a way to directly access circlecrop.php and it will work. Any help is greatly appreciated!
Edit: I've updated the url that has the errors, maybe that's more helpful.
You need to include if your website placed on root directory
RewriteBase /
If it place in test folder for example use this.
RewriteBase /test/
simply use site_url() on every link and action instead of base_url().
This worked for me:
I replace .htaccess content by the following:
RewriteEngine on
RewriteCond $1 !^(index.php|application/themes|application/theme_path|images|assets|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Update your base_url according to your live host in config.php
$config['base_url'] = 'SET YOUR SITE URL HERE';
config.php is located in /application/config

rewrite url using htacess

I have test project folder called "prj". In that, I have one file called test.php.I want something like
http://localhost/prj/test.php?t=123
should be rewritten like
http://localhost/prj/test.php
any help will be appreciated
Create a .htaccess file with:
RewriteEngine on
RewriteRule ^prj\/test.php$ prj/test.php?t=123 [NC]
Edit
If your htaccess file is located in the prj folder:
RewriteEngine on
RewriteRule ^test.php$ test.php?t=123 [NC]

Categories