How to hide folder directory? with htaccess is it possible? - php

My website has the structure www.mywebsite.com/app/views/pages/dashboard.php however I wanted it to be only www.mywebsite.com/dashboard.php I tried to do this with htaccess but I'm not getting results
This is my complete htaccess
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteEngine on
RewriteRule ^dashboard\.php$ app/view/pages/dashboard.php

Related

PHP script images are missing after migration and changing directory

I have installed my PHP script in a directory of my website psc.af/photo after migration to another domain and in its main directory (public_html in cPanel) everything works fine but the images are not showing up. When i inspect the image link it shows mynewdomain.com/photo/images which is not and it got the photo directory from my previous installation in sub directory. So i cant see the images.
I have tried to change my app url and its fine, the only issue is missing images.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:cDd2jFWmOeQajBVf+UbCcCW9v0OxeZC/w+mp8qwgw0g=
APP_DEBUG=true
APP_URL=http://psc.af/
This is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
Options -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
<Files composer.json>
order allow,deny
deny from all
</Files>
<Files composer.lock>
order allow,deny
deny from all
</Files>
<Files .env>
order allow,deny
deny from all
</Files>
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Remove index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
</IfModule>

ignore folder from htaccess rewriterule

I don't understand htaccess at all except from it's function to "pretify" url's and I know this question has been asked a milion times, i have tried nearly all of them but none of the answers worked for me.
So basically i have givin my own go at creating a cms and a structure to go with it. the "cms" is located in a subfolder called system with it's own respectable index.php
my htaccess is configured to take the var "page" and retract the .php extension from it in the url. everything works fine until i start calling pages from the system subfolder.
My question is, how can i get htacces to ignore this folder and continue it's rewriting rule despite the user currently being located in the subfolder?
my htaccess is set up as follows:
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\\.]+)$ $1.php [NC,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [QSA]
<Files .htaccess>
order allow,deny
deny from all
</Files>
ErrorDocument 404 home
ErrorDocument 403 home
#php_flag display_errors off
Have it like this:
ErrorDocument 404 /home
ErrorDocument 403 /home
RewriteEngine On
Options +FollowSymLinks
# skip subfolder from any rules
RewriteRule ^subfolder(/.*)?$ - [L,NC]
# add .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^system/(.*)$ system/index.php?page=$1 [L,NC,QSA]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
<Files .htaccess>
order allow,deny
deny from all
</Files>

mod_rewrite worked and now doesn't

I created a new apache2 server. Htaccess loads and works but I can't seem to get .php to not show. The page will go to 404 instead of loading the php version.
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
</IfModule>
<Files ~ "\.tpl$">
Order allow,deny
Deny from all
</Files>

htaccess rewriterule not working in codeigniter

Here I am trying to remove index.php from URL in my codeigniter application.
For that, i write .htaccess file like this:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
# RewriteBase /projectname/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php [PT]
It is working in xx.xx.xx.xxx server and mydomain.com. Here i tried to make a same copy to another server yy.yy.yy.yyy. In this, rewrite URL is not working. If i use 'yy.yy.yy.yyy/index.php/login', its working correctly. But 'yy.yy.yy.yyy/login', it throws me 'The requested URL /projectname/login was not found on this server.' error.
For your main directory .htaccess try this and then remove index.php from config.php
Options +FollowSymLinks
Options -Indexes
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Do not touch the .htaccess files in applications directory's.

Wordpress rewrite rules conflicting with real paths and filenames

I'm recreating my employers website, it currently uses WordPress,
I have created a new directory within the /public_html/ folder named dev. While the dev folder is empty - It will display directory contents as expected. The moment I throw an index.php file in there, I get sent back to a 404 error.
The contents of index.php is simply <h1>Working</h1>
Looking into the .htaccess of the primary directory
# 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>
It appears that it should already be ignoring the rule if the requested filename is infact a real file or directory.
The entire .htaccess file.
RewriteEngine on
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
#The next line modified by DenyIP
order allow,deny
#The next line modified by DenyIP
#deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName ant.com.au
# 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
<Files 403.shtml>
order allow,deny
allow from all
</Files>
Definitely looks like there should be no conflict whatsoever trying to navigate to a literal directory and/or file
Any help is greatly appreciated
This was actually very simple to fix:
I just added a rewrite condition: RewriteCond %{REQUEST_URI} !^/dev/
Full rewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/dev/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Categories