How would I update these rules so both can run in .htaccess? - php

I'm needing to merge both of these inside my .htaccess folder. If the top one runs, WordPress works properly but my forum does not. If the bottom one runs it's reversed. I've done some research and I found it's because I have multiple RewriteBases in the code. I'm needing some help getting them merged together though. Thank you.
<IfModule mod_setenvif.c>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
</IfModule>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forum/api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /forum/404error.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forum/index.php [L]
</IfModule>

I think I figured it out. This is at least working for me.
<IfModule mod_setenvif.c>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
</IfModule>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forum/api/.* index.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^forum/\.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /forum/404error.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forum/. /forum/index.php [L]
</IfModule>

Related

Index of / in Laravel cPanel

I am facing issue "Index of /" while accessing my website that i have uploaded on cPanel direct root. Even I have .htaccess file in public_html
I try this htaccess code.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ public/index.php [L]
</IfModule>
You need to disable indexing your paths from htaccess. Add this line to htaccess above:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ public/index.php [L]
</IfModule>
<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>

laravel 5.6 not redirecting properly

I am setting laravel 5.6 in a subfolder but it is giving error the page is not redirecting properly. I have tried everything with the htaceess. I have setup the htacess at the root folder as well as the public folder but it is not working
My root htaccess is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and here is my htacess for public folder
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /charity-frontmode/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Please help! Thanks in advance
Try the following
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

htaccess/url rewrite with Silex, XAMPP, and multifolder structure

I've tried searching multiple previous threads on setting up url rewrite correctly for a Silex application on XAMPP, but still can't figure this issue out. Here is what I am trying to accomplish.
I am using XAMPP and here is the structure of my htdocs folder:
- xampp
- htdocs
- app1
- app2
- app3 <silex application>
.htaccess file (outside of web folder)
- web
index.php file
I can currently do http://localhost:50000/msk/web/cte. My question is how do I get rid of "web" from this (i.e. http://localhost:50000/msk/cte)
I feel like I'm missing something minor, but I can't figure it out.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /msk/web/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
LoadModule rewrite_module modules/mod_rewrite.so is un-commented in my config.
I am not using virtual hosts either.
Thanks
Try this one
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You can try :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /msk/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^cte/url-word$ cte/redirect-page [L]
</IfModule>
use the following .htaccess in /msk directory:
Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(web)
# ------- browser looks for them on base url -------- ex: /images/logo.png
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php
</IfModule>
and use this .htaccess in your /msk/web directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>

Laravel not detecting files from public folder

hello people below is code of .htaccess inside public folder...
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteRule ^ index.php [L]
# Redirect Trailing Slashes...
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
As though i have some images inside public folder...'not found error message is displayed' ...anyways to fix this???
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
try changing it to this make sure this .htaccess is inside of your public folder.
inside app i have this other .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
and laravel works just fine!
Try this code. It will work prefect in Shared Server or other Server.
For Fix this issue. i did some steps :
copy all files from Public Folder to root Folder.
change path in index.php means replace it '../' to "/".
update .htaccess file with this code.
I have also added a code for Hide env file. if you not add that code then anyone can see your env file.
<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]
#RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.woff|\.woff2|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_URI} !(\.svg|\.woff|\.woff2|\.ttf|\.css|\.js|\.png|\.jpg|\.gif|\.pdf|\.jpeg|\.docx|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|admin|userimage|ckedit_images|video|thumbnail|fonts|amenities-pic|img|propert|property_video|vendor|photos|files|doc|flags|1x1|4x3)/(.*)$ public/$1/$2 [L,NC]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
#hide a Specifuc Laravel .env File
<Files .env>
order allow,deny
Deny from all
</Files>

.htaccess returns 500 for a simple redirect in Laravel

I have created an app in Laravel.
My initial .htaccess was:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And it worked properly for the domain api.viglug.org.
After I added the m.forum.viglug.org domain (with the same root directory of api.viglug.org).
At this point was exactly the same to call api.viglug.org and m.forum.viglug.org.
I wanted to use the m.forum.viglug.org for the folder api.viglug.org/mobile so I thought it would have worked with this .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} m\. [NC]
RewriteRule ^(.*)$ index.php/mobile/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I was wrong. It keeps returning error 500 if I use m.forum.viglug.org, while api.viglug.org works as expected.
How can I fix this?
The original rewrite only runs on files which do not exist as real files or directories, due to these two conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Have you tried adding those two conditions above your additional rule?
# Mobile site
RewriteCond %{HTTP_HOST} m\. [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/mobile/$1 [L]
# Normal site
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Categories