Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Issue in the route, redirect to parent domain, if you put / at the end of url #3595

Closed
SyedMuradAliShah opened this issue Sep 3, 2020 · 3 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@SyedMuradAliShah
Copy link

SyedMuradAliShah commented Sep 3, 2020

Description
Route redirect to parent domain when I put / at the end of the URL

For example:
My URL is http://localhost/pep_digital/dashboard
When I put / at the end like http://localhost/pep_digital/dashboard/
It redirects me to http://localhost

Please note my base URL is: http://localhost/pep_digital/

And the following routes I tried for all the issue is the same.

$routes->group('dashboard', function ($routes) {
	// Other routes
});

or
$routes->match(['get'],'dashboard', 'Dashboard::index');
or
$routes->get('dashboard', 'Dashboard::index');

Edit
After visiting this link http://localhost/pep_digital/dashboard/test/
It redirects me to http://localhost/dashboard/test
And
https://localhost/pep_digital/dashboard/test/dashboard/test/
It redirects me to https://localhost/dashboard/test/dashboard/test

It removing the 1st segment from the url.

CodeIgniter 4 version
4.0.4

Affected module(s)
I think this one
\system\Router\RouteCollection.php

Context

  • Windows 10
  • PHP version 7.2.19

NOTE
I have tried it with the latest updated branch.

@SyedMuradAliShah SyedMuradAliShah added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 3, 2020
@michalsn
Copy link
Member

michalsn commented Sep 3, 2020

Please try to edit your RewriteBase in .htaccess file. Something like this probably should help

RewriteBase /pep_digital/

I'm closing this, since it doesn't seem to be a bug, but feel free to continue conversation.

@michalsn michalsn closed this as completed Sep 3, 2020
@SyedMuradAliShah
Copy link
Author

Can you please review my .htaccess, by defining the RewriteBase the issue isn't fixed.

# Protect .env
<Files .env>
Order Allow,Deny
Deny from all
</Files>

# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
	Options +FollowSymlinks
	RewriteEngine On

	# If you installed CodeIgniter in a subfolder, you will need to
	# change the following line to match the subfolder you need.
	# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
	# RewriteBase /

	# Redirect Trailing Slashes...
	RewriteCond %{REQUEST_FILENAME} !-d
    	RewriteRule ^(.*)/$ /$1 [L,R=301]

	# Rewrite "www.example.com -> example.com"
	RewriteCond %{HTTPS} !=on
	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
	RewriteRule ^ http://%1%{REQUEST_URI} [R=301,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 the front controller, index.php
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.*)$ index.php/$1 [L]

	# Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</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>

# Disable server signature start
    ServerSignature Off
# Disable server signature end

@michalsn
Copy link
Member

michalsn commented Sep 3, 2020

Please copy the default .htaccess file: https://github.com/codeigniter4/CodeIgniter4/blob/develop/public/.htaccess and then change RewriteBase as described previously. If that won't help, please start a thread on the Forum since we deal only with bugs here.

@SyedMuradAliShah SyedMuradAliShah changed the title Bug: Issue in the route, redirect to parent domain, if you put / at the end or url Bug: Issue in the route, redirect to parent domain, if you put / at the end of url Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants