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>
Related
A client has requested a website built and now that it has been built, they've requested it be hosted alongside their existing website but in a subdirectory (example.com/example/path).
What I'm dealing with now is figuring out the required apache rules to host this correctly. I've uploaded the entire project structure to that directory. Within the public directory (/example/path/public) I have the following .htaccess file (henceforth I'll refer to this as the Laravel .htaccess):
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /example/path
# 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]
# Serve Cached Page If Available...
RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{DOCUMENT_ROOT}/page-cache/pc__index__pc.html -f
RewriteRule .? page-cache/pc__index__pc.html [L]
RewriteCond %{DOCUMENT_ROOT}/page-cache%{REQUEST_URI}.html -f
RewriteRule . page-cache%{REQUEST_URI}.html [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<FilesMatch ".(jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot|otf)$">
Header set Cache-Control "max-age=2628000, public"
</FilesMatch>
<FilesMatch ".(css|js)$">
Header set Cache-Control "max-age=86400, public"
</FilesMatch>
I have added the RewriteBase line based on me trying to find a solution to this.
Within the base .htaccess file (/example/path/.htaccess), I have the following:
<IfModule mod_alias.c>
Alias /example/path /home/www/<user>/html/example/path
<Directory "/home/www/<user>/html/example/path">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</IfModule>
The problem is however that this returns an internal server error. I've tried other potential solutions that don't use Alias that instead return 40X errors.
I need to be able to have the Laravel site fully working when a user visits example.com/example/path. I've tried numerous solutions over the past 90 minutes and none have worked.
What is the correct solution to my situation?
In public folder we have hosted 8 platforms and each platform's root directory we have this .htaccess configuration. hope this helps you.
<ifmodule mod_rewrite.c>
<ifmodule mod_negotiation.c>
Options -MultiViews
</ifmodule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</ifmodule>
I did this recently too. My client had their Wordpress set to resolve at as the Document root (/var/www/html), but they also wanted their Laravel app "installed" in a subfolder of Wordpress and named "hq"
This however would be a security problem, because we only want Laravel's Public folder exposed, and not the application files. To solve this problem, I used the power of symbolic links!
The Laravel app was placed below the Document root at:
/var/www/laravel
I then exposed Laravel's public folder in the DocumentRoot with the command "ln -s symlinkLocation symbolic-link-name"
ln -s /var/www/laravel/public /var/www/html/hq
In the above line, you can see that "hq" is not an actual folder, but instead a symlink to /var/www/laravel/public
(which is where Laravel's index.php entry point is, the css, js etc)
Here is what the symbolic link looks like:
I also made a symbolic link to the storage folder:
ln -s /var/www/laravel/public/ /var/www/laravel/storage/app/public
Which accomplishes what "php artisan storage:link" accomplishes.
For reference, here is what my laravel .htaccess looks like:
The .htaccess in /var/www/laravel/public/.htaccess was
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Hope this helps
create a htaccess file in root directory of project
and add the following lines :
#disable directory browsing
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
#PROTECT ENV FILE
<Files .env>
order allow,deny
Deny from all
</Files>
#PROTECT htaccess FILE
<Files .htaccess>
order allow,deny
Deny from all
</Files>
I am trying to remove frontend from my url address. My url address is before rewriting localhost/abc/frontend/home/index.php and want localhost/abc/ I tried to do this by using .htaccess and I did but when I use htaccess it render me index.php for all menus.. my menus are store in
views
|
|--home|
|--menus
My file structure is like this ..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/$1 [L]
</IfModule>
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
Above codes are of .htaccess of root folder and
its htaccess file stored in home folder
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
#AddType application/x-httpd-php54 .php
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.
I have a php site in the root folder with an htaccess. I have a blog in a subfolder but the wordpress blog is not loading because of the blog htaccess is conflicting with the htaccess in the root folder.
Here is the two htaccess files
Root Folder
#Options +FollowSymLinks
Options -Multiviews
RewriteEngine on
#RewriteBase /lasercap/public_html/
RewriteCond %{REQUEST_URI} !^/blog/
#Map http://www.example.com/x to /jekyll/x unless there is a x in the web root.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^/lasercap/public_html/
RewriteRule ^ISHRS2013$ ISHRS2013.php
RewriteRule ^(.*)$ /lasercap/public_html/$1
#DirectoryIndex /lasercap/public_html/site-offline.html index.html
DirectoryIndex /lasercap/public_html/index.php
htaccess for Wordpress Blog
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/blog/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/failed_auth.html$
RewriteRule ^.*$ - [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Can anyone help with htaccess. i need your help. Thank you
I'm trying to make a subdirectory on wordpress
http://wpsite.com/codeigniter,
http://wpsite.com/someothersubdir
But when I go to that url, it always redirects back to the wordpress site with the "page not found"
Here is the wordpress root htaccess file
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
# 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
How can I make sub directories separate from wordpress? Thank you
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/codeigniter/
RewriteCond %{REQUEST_URI} !^/someothersubdir/
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
In my case the issue was in the htaccess of the subfolder (where I have another wordpress running, for testing purposes). So I had to change the .htaccess of the subfolder to this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /someothersubdir
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress