.htaccess file and folder with the same name - .htaccess

I am new at .htaccess and I have a PHP file called products.php and a folder with the same name called /products.
I want to create a friendly URL for the products page of my website a I would like to know if it is possible to execute the products.php file outside the folder /products.
I am using the .htaccess code below.
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^products/([a-z0-9-]+)/([0-9]+)/?$ products.php?id=$2&nome=$1 [NC]
Thanks

Did you try it and it didn't work ? if it didn't, try removing this line :
RewriteCond %{SCRIPT_FILENAME} !-d

Related

How to fix double href in .htaccess?

Following a tutorial I set up routes for a webapp written in PHP. Everything works until certain point. For instance, when I click a link from the base it takes me to the desired page e.g. about/culture. But when inside culture page I got about/about/culture or about/about links what is wrong because these routes don't exist. I pretty new on this, How I can fix it up?
My .htaccess file is this:
RewriteEngine On
RewriteBase /PHP/20-DI_Container/
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]

htaccess routing codeigniter

I have a problem with my routes. I have my images in sources/ folder but when the image is missing it cause to load the website and future problem with system overloading.
Htaccess:
RewriteCond $1 !^(index\.php|robots\.txt|sources|uploads|captcha|sitemap\.xml|_gapi|robots\.txt|googleaac809c6bcbeb4e8\.html|googlebaf6b56ae3013092\.html|feeds|temp)
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
This should cause to load files from those folders - working well by this point
But when there is image missing for example:
<img src="uploads/non_existing_image.jpg"> the image wont load but when I copy the URL the website will load correctly and after some time my server ends up with 500 Error.
Is there any way how to solve this in htaccess/php ?
I want to end up with 404 error on that link
Don't use .htaccess for this, just Add the index.html file to your images folder also add the index.html in CSS and JavaScript folder. When someone try load you folder index.html is auto load and didn't allow your images etc.
It will give result like this
i also use a htaccess file with codeigniter, even though mine is quite smaller then yours:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
to explain: RewriteEngine On enables the rewriting of the url,
the RewriteCond %{REQUEST_FILENAME} !-f tells htaccess that the requested file should not be an existing file,
the RewriteCond %{REQUEST_FILENAME} !-d tells htaccess that the requested file should not be an existing directory.
this way you dont need to exclude all the seperate files and/or extentions and/or directories.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Just add this to your .htaccess file

No input file specified error. Codeigniter 3 and go daddy subdomain

I am getting following error after opening the codeigniter base url:
"No Input file specified". I know that it has something to do with htaccess file but can't make it work.
my htaccess file content:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Go daddy directory structure: htaccess file is at root folder of subdomain.
Your htaccess file is fine you need to check paths in controller
i guess it could be view file missing
$this->load->view('file_view', $data);
in views folder it is named "file_view.php"
also make sure file paths are correct
if you are calling a module module file exists under modules folder
check $route['default_controller'] = "frontpage"; in routs.php under config folder for above line frontpage.php must exist in views folder
add rewrite base
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Removing 2 directory and php from url

My current url is:
http://example.org/dir1/dir2/profile.php?username=someone
I want it to look like this:
http://example.com/someone
My .htaccess file is in public_html folder and it is completely empty.
Please, can you help me?
Try this :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /dir1/dir2/profile.php?username=$1 [QSA,L,NC]
The conditions make sure you don't rewrite any existing file/directories on the server.

Mask folder name and show only subdirectory

I have this structure:
http://mywebsite.com/folder/myapp1
http://mywebsite.com/folder/myapp2
http://mywebsite.com/folder/myapp3
How can I do to hide "folder" in the URL using .htaccess?
That is, if I enter
http://mywebsite.com/myapp1
I want it to display the contents of
http://mywebsite.com/folder/myapp1
Thanks in advance!
You can try this. This should work for you inyour .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) folder/$1 [L]

Resources