i'm currently stucked at a redirection issue for my PHP project. My Project has the following structure:
root
--config
--classes
--sites
--libs
--web
----assets
----index.php
--.htaccess
The main folder is the "web" Folder where all of my Code and Logics are loaded.
Is it possible to set a redirection in my .htaccess-File to load all the Content from the "/web" folder without displaying it in the URL ?
My .htaccess-File has following Content:
RewriteEngine On
RewriteBase /web
<Files *.php>
deny from all
</Files>
<Files "index.php">
Order Allow,Deny
Allow from all
</Files>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ ?site=$1 [QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ ?site=$1&slug1=$2 [QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ ?site=$1&slug1=$2&slug2=$3 [QSA]
RewriteRule ^index\.html$ / [NC,R,L]
RewriteRule ^index\.php$ / [NC,R,L]
Related
I have a CodeIgniter project and I recently added a Laravel Lumen API, so the folder structure is the following
Project
- api/
- application/
- public/
- system/
- .htaccess
- index.php
Inside the api/ folder resides the Lumen framework. Locally it's working perfectly, by accessing the url localhost/example.com/api/test it returns 200 HTTP code.
.htaccess codeigniter root folder:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [QSA,R,L]
RewriteCond $1 !^(index\.php|public|robots\.txt)
RewriteCond $1 !^([^\..]+\.php|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
.htaccess lumen api folder:
<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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<Files .env>
Order allow,deny
Deny from all
</Files>
The errors:
By accessing example.com/api/test it returns 404 HTTP code by codeigniter
By accessing example.com/api it returns 404 HTTP code by lumen
Solved.
Well, the .htaccess worked without any problem in localhost because I have apache installed, which I don't have in the production server.
The server is running Nginx and not Apache, which I only find out after requesting support.
I use RewriteRule to shorten the links from ?s=xxx to /xxx - but I have some problems that I cant access files in some folders. To help with that I have make an exception in the rule as:
RewriteRule ^(inv.*) $1 [L]
This because I have .pdf files in the folder "inv".
But the problem is that I also have some sites that is called /invitation. The problem is that this link gives 404 error.
If I remowe the line above, the /invitation works - but then I get 404 error on the /inv/xx.pdf.
How can I change the RewriteRule that makes both works.
Thanks.
This is my entire .htaccess file:
DirectoryIndex i.php index.php index.html
RewriteEngine On
RewriteRule ^robots.txt - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule ^(inv.*) $1 [L]
RewriteRule ^([^/]+)/?$ /?s=$1 [NC,L]
RewriteRule ^(nyhet)/([^/]+)/?$ /?s=$1&n=$2 [NC,L]
RewriteRule ^([^/]+)/([^/]+)/?$ /?s=$1_$2 [NC,L]
ErrorDocument 404 http://www.domain.com/404
ErrorDocument 403 http://www.domain.com/404
disable reportory contenu by
Options All -Indexes
then fix rules of files
<Files ~ "([.][^][*])^.*\.">
order allow,deny
deny from all
satisfy all
</Files>
This is my first question.
I have an wp-site on the root directory and it's own .htaccess file.
RewriteEngine off
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/katambi/public_html/php.ini
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
# 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
On another directory I've SocialEngine network site. It also has .htaccess file.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
Problem: when i enter to package and plugins page it display 404 error. =(
When i delete code between
# BEGIN WordPress
and
# END WordPress
wp-site down but social network runs correct.
Thanks for your answers.
The code between # BEGIN WordPress and # END WordPress is redirecting all request to root directory's index.php. You need to make sure that requests to SocialEngine's directory is not being redirected. So you can try this solution- .htaccess & Wordpress: Exclude folder from RewriteRule
I've added the following to my .htaccess to properly redirect any visitors from http://domain.com to http://www.domain.com ... but I still can't get it to work with subpages...ie http://domain.com/subpage is not yet redirecting to http://www.domain.com/subpage .
Here is what I have in my htaccess now:
<Files wp-config.php>
order allow,deny
deny from all
</Files>
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R]
</IfModule>
So the question is what else would I need to add or update in my htaccess to get this working?
Many thanks for your suggestions!
You have the redirect happening after you've done routing to index.php, it needs to happen before any routing rules get executed. Try swapping them around:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
(also added the [NC] flag so case isn't checked in hostname match)
I can't hide Codeigniter index.php on XAMPP 1.7.3
URL:
http://localhost/Servidor/agentesRainbow/index.php/agentes/tony
tony is an argument
My actual .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Servidor/agentesRainbow/
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|css|public|)
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>
My routes.php:
$route['agentes/(:any)'] = "agentes/index/$1";
$route['default_controller'] = "agentes";
$route['scaffolding_trigger'] = "";
My config.php:
$config['base_url'] = "http://localhost/Servidor/agentesRainbow/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
On httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory /Servidor/agentesRainbow/>
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Add this line to the REQUEST_FILENAME conditions:
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
Here is the updated .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Servidor/agentesRainbow/
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|css|public)
RewriteRule ^(.*)$ /Servidor/agentesRainbow/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /application/errors/404.php
</IfModule>
Hope it solves your problem!
I think the bar at the end of the rewrite condition is causing a problem. At least it broke the rewriting for me.
RewriteCond $1 !^(index\.php|images|css|public|)
Try removing the bar.
RewriteCond $1 !^(index\.php|images|css|public)
base_url should be just "http://localhost";
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|other|directories|you|want|accessible|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>