Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freixa21's avatar

Adding a slash at the end of url + page loading with different url's

Hi,

So I'm migrating a website from WordPress to Laravel. I'm making the same website and I need to be sure the URLs stay the same to avoid SEO problems. In the WordPress website all URLs end with a slash and in Laravel, every existing route URL can be utilized both with and without a trailing slash, and you'll receive a HTTP 200 response in either case. However, for search engine optimization purposes, this is not ideal, as the URLs are considered different and therefore result in duplicated content.

What I've done: I installed a package called illuminatech/url-trailing-slash. What this package does is add a slash at the end of the URL. So for example, a route www.domain.com/contact will redirect to www.domain.com/contact/

I followed all the instructions and everything is working fine, now the routes are being redirected with the requested route with a slash at the end.

What I need to fix: After testing, I realized that the route now can be accessed via www.domain.com/contact/ (which is correct and how it should be) and www.domain.com/responsive/public/contact/

My Laravel project is located in public_html/responsive

My .htaccess file inside public folder looks like this:

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Remove public URL from the path
RewriteCond %{REQUEST_URI} !^/responsive/public/
RewriteRule ^(.*)$ /responsive/public/ [L,QSA]

# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I don't know if .htaccess file located in public_html has any effect on this matter but I'll add it here anyway:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^laravel.domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.laravel.domain.com$
RewriteCond %{REQUEST_URI} !responsive/public/
RewriteRule (.*) /responsive/public/ [L]
AddHandler application/x-httpd-php81 .php .php5 .php4 .php3

I hope my explanation was good enough and wish somebody can help me out with this.

Very much appreciated!

0 likes
9 replies
Snapey's avatar

My Laravel project is located in public_html/responsive

This is a big security concern (SEO aside). Only the public folder should be accessible to the world, and should be set as the document root

You really need to fix this before worrying about SEO (the problem being eliminated anyway when you fix the hosting)

freixa21's avatar

@Snapey Hi, thank you very much for your advice.

How should I proceed? Do I have to move all my files or I need to change my .htacess file?

freixa21's avatar

To be more clear:

public_html is the root folder of my hosting, here you can find:

.git
.htaccess
Default.html
README.md
composer.json
composer.lock
responsive
vendor

inside responsive folder I have

README.md
app
artisan
bootstrap
composer.json
composer.lock
config
database
dist
package-lock.json
package.json
php_errorlog
phpunit.xml
public
resources
routes
server.php
storage
tailwind.config.js
tailwindcss
tests
vendor
webpack.mix.js

And then in public:

.htaccess
css
favicon.ico
fonts
images
index.php  
js  
mix-manifest.json 
php_errorlog
robots.txt 
vendor
freixa21's avatar

@Snapey for the first link I have a 403 forbidden code and 404 not found code for the second one. I guess that's a good think.

kokoshneta's avatar

@freixa21 So if you FTP into your account, you cannot go higher than public_html? You do not have access to any folders above that at all?

freixa21's avatar

@kokoshneta Yes I do. The higher folder contains diferent folders for the domain and subdomains associated, like:

├──  domain.com
├──  laravel.domain.com

The Laravel project is inside the subdomain folder (laravel.domain.com) and another WordPress site is in domain.com

Then inside laravel.domain.com folder I have 3 folders:

laravel.domain.com/
    ├── logs
    ├── public_html
    ├── webstats

Inside public_html i have:

laravel.domain.com/public_html
	├── .git
    ├── .htaccess
    ├── Default.html
    ├── README.md
    ├── composer.json
    ├── composer.lock
    ├── responsive
    ├── vendor
kokoshneta's avatar

@freixa21 That is not how it should be.

You should have all your Laravel files inside laravel.domain.com, which is not accessible via a browser. Then, depending on what you have access to, you should either,

  • if you have access to changing the document root for the domain, change it to be the laravel.domain.com/public folder
  • if you can create symlinks, delete the public_html folder and make a symlink from the public folder to public_html
  • if you don’t have access to either of those things, rename the public folder to public_html and then tell Laravel to use public_html as the public folder with the Application::usePublicPath() method (for Laravel 10) in bootstrap/app.php
da_Mask's avatar

I think the best thing you can do is store your laravel project outside of public_html, and then hopefully there is a way of creating a symlink in your hosting from public_html -> project/public .

Please or to participate in this conversation.