Laravel 5.4 Redirection in the server - .htaccess

I have a Laravel 5.4 project under the folder www of Wampserver64.
The project folder name is AxilogicV2.
When I visit localhost/AxilogicV2 it will take me to the login screen, but after login succeeds it takes me to 'localhost/'. (The form should make a post request to itself ('/') and will be redirected to ('/view').
Every redirection ignores 'AxilogicV2'.
Example: localhost/AxilogicV2/view/9408 => localhost/view/9408.
Here is my .htaccess file. I tried a bunch of redirect rules but didn't work.
Options -MultiViews
RewriteEngine On
RewriteBase /AxilogicV2
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
In httpd.conf file Rewrite is enabled and Override is set to All.
Edit: I took out the index.php from public folder and made appropriate corrections so that it will find the right bootstrap folder and access autoload.php and app.php

Related

Yii2 .htaccess redirect to backend part

I have installed Yii2 advanced app and what i am trying to do now is to redirect this url htpp://site/admin to the backend ( admin ) side. What i tried so far is:
AddDefaultCharset utf-8
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# Make the backend accessible via url: http://site/admin
RewriteRule ^admin$ $admin.php [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule ^static - [L]
I am not familiar whit .htaccess and i am not pretty sure what is the right way. This code is what i found after googling. The .htaccess file is in the app/backend/web/.htaccess. Can you point me the right way? Thank you in advance!
easy :
RewriteEngine On
# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend)/web/ - [L]
# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^admin(/(.*))?$ backend/web/$2 [S=1]
# handle the case of frontend
RewriteRule .* frontend/web/$0
# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php

.htaccess issue | Codeigniter

I'm relatively new to Codeigniter and MVC. But, have successfully made two apps 'Locally'. While exploring, I found a way to remove 'Index.php' from the URL and also about custom routes. The .htaccess file that i have works like charm locally, but when trying to host it; there is a issue 505 internal server issue
Here is the first .htaccess code that i have (works locally) :-
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
When i use the code above there is an error. And, the app works only when .htaccess is removed. (I then have to use the inconvenient long URLs)
After a brief research and using different .htaccess without success, i asked one of my friends who has a Hosted CI app successfully running. He sends me a file which leads me the landing page without any problem; but, cant call any functions with/without using routing .i.e. If i use the custom routed URl (www.mySite.com/contact) then also it leads me to the landing page, the same with actual URL scheme (www.mySite.com/welcome/contact_page)
The new code here:-
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Using this code shows me the landing page but i cannot navigate any further from there. When i try to call a function the landing page reloads. This, I think is because of the last error Handling Code (ErrorDocument 404 /index.php)
Does anyone know what the solution the problem might be??
questions
Why doesnt the first .htaccess code work when hosted?
What may be the issue with the second available .htaccess file??
Do you guys have better .htaccess file? If yes, can you post it here??
Try this .htaccess (Codeigniter Recommended )
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
or
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In application/config/config.php
$config['base_url'] = 'http://stackoverflow.com/';
$config['index_page'] = ''; # Should be empty
And make sure Controller name, Model names are in proper way. Bcz Linux Host is an Case-Sensitive.

.htaccess Rewrite Rules online and localhost

On this website and on wamp localhost
http://www.aproapetot.ro/page.php?categ_id=1&id=1
http://localhost/aproapetot-backup/page.php?categ_id=1&id=1
I tried to build the .htaccess, but without any success.
This is what I wrote for online website:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
and this for localhost
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /aproapetot-backup/
RewriteRule index.php index.html
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
Someone please give a little help.
It's a website with jokes so after .ro/page.php?categ_id=1&id=1 I have a category(1) and subcategory(1).
I want to have like this
.ro/jokes/doctors instead of how is now.
I'm not entirely sure what you want based upon the htaccess content, but what I do understand is that you want /jokes/doctors is rewritten to /pages.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !pages.php [NC]
RewriteRule ^(.*)$ /pages.php [L]
The above code will rewrite all requests to pages.php, as long as:
%{REQUEST_FILENAME} "!-f": The file itself does not exist on the server.
%{REQUEST_FILENAME} !pages.php: The request is not made to pages.php (meaning that it already has been rewritten)
Finally you can use PHP to obtain the parameters using:
/* Get all parameters from the URL */
$_GET['path'] = rawurldecode( $_SERVER['REQUEST_URI'] );
/* Remove double slashes and backslahses and convert all slashes and backslashes to '/' */
$_GET['path'] = preg_replace( array('#[/\\\\]+#', '/(\/\.)+(\/)/'), '/', $_GET['path']);
$_GET['path'][0] should contain "jokes"
$_GET['path'][0] should contain "doctors"
==edit==
Redirecting using htaccess (not the best method)
Redirect 301 /page.php?categ_id=6&id=0 /anecdotes
Redirect 301 /page.php?categ_id=1&id=1 /jokes/doctors
PHP (or other server side script). You can perform a check if the url is in fact having numbers (see $_SERVER['REQUEST_URI']) and ifso, add some header redirection to your page.
<?PHP
header('Location: www.aproapetot.ro/' . $cat . '/' . $subcat );
?>

Remove subfolder with htaccess

This is the architecture of my website :
/
app/
index.php
...
libs/
lib1/
file.php
lib2/
...
I need to access index.php by this url : domain.com/index.php
I tried this :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)app
RewriteRule ^(.*)$ app/$1 [L]
It works, but inside my index.php, I call for example :
include('../libs/lib1/file.php');
It's doesn't work because this path refer to root now...
And I can't access to domain.com/libs anymore, because it's looking for domain.com/app/libs.
How can I do ?
The include() shouldn't care what the path the browser sees. That should be based on the local filesystem on the server. But your rules are affecting direct access to the libs, so try adding a few more conditions:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^app/
RewriteRule ^(.+)$ app/$1 [L]
RewriteRule ^$ app/index.php [L]
This makes it so requests for existing files or content won't get routed through the app folder.

How do I create a exception for a subdirectoy so the main HTacces won't interfere with subdirectory?

Well I have a main website which runs ELGG1.8 and it needs it's own created htaccess to function properly. But now I want to create a subdirectory in my main folder and the main /htaccess is messing it up, I cannot acces the folder, just run html files, no php, nothing..
How can I edit this .htaccess to make an exception?
<IfModule mod_rewrite.c>
RewriteEngine on
# If Elgg is in a subdirectory on your site, you might need to add a RewriteBase line
# containing the path from your site root to elgg's root. e.g. If your site is
# http://example.com/ and Elgg is in http://example.com/sites/elgg/, you might need
#
#RewriteBase /sites/elgg/
#
# here, only without the # in front.
#
# If you're not running Elgg in a subdirectory on your site, but still getting lots
# of 404 errors beyond the front page, you could instead try:
#
#RewriteBase /
# In for backwards compatibility
RewriteRule ^pg\/([A-Za-z0-9\_\-]+)$ engine/handlers/page_handler.php?handler=$1&%{QUERY_STRING}
RewriteRule ^pg\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&page=$2&%{QUERY_STRING}
RewriteRule ^tag\/(.+)\/?$ engine/handlers/page_handler.php?handler=search&page=$1
RewriteRule ^action\/([A-Za-z0-9\_\-\/]+)$ engine/handlers/action_handler.php?action=$1&%{QUERY_STRING}
RewriteRule ^cache\/(.*)$ engine/handlers/cache_handler.php?request=$1&%{QUERY_STRING}
RewriteRule ^services\/api\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/service_handler.php?handler=$1&request=$2&%{QUERY_STRING}
RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/?$ engine/handlers/export_handler.php?view=$1&guid=$2
RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$ engine/handlers/export_handler.php?view=$1&guid=$2&type=$3&idname=$4
RewriteRule xml-rpc.php engine/handlers/xml-rpc_handler.php
RewriteRule mt/mt-xmlrpc.cgi engine/handlers/xml-rpc_handler.php
# rule for rewrite module test during install - can be removed after installation
RewriteRule ^rewrite.php$ install.php
# Everything else that isn't a file gets routed through the page handler
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)$ engine/handlers/page_handler.php?handler=$1 [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&page=$2 [QSA]
</IfModule>
Right underneath the RewriteEngine on, in your htaccess file, add this rule to allow requests for the directory to pass-through:
RewriteRule ^directory/to/pass/through - [L]
This makes it so when someone requests http://your.domain.com/directory/to/pass/through, the rewrite engine will let that through without interferring with it.

Resources