Our site home page URL is https://example.com
But the corresponding CMS Page in Magento 2.4.4 has home as the URL Key.
As a result, the home page can also be browsed at https://example.com/home
We do not want to allow it.
Things we tried:
- Set the
URL Keyto empty- Result:
This identifier is reserved for "CMS Home Page" in configuration.
- Result:
- Set the
URL Keyto/- Result:
This identifier is reserved for "CMS Home Page" in configuration.
- Result:
- Set a URL Rewrite, from
hometo/- Result:
Request Path for Specified Store already exists.
- Result:
So what? Are we condemned to have the home page also browsable from an arbitrary URL?
-
im curious as to why this is an issue? your homepage is likely also browsable by the similarly arbitary example.com/index.phpbjornredemption– bjornredemption2023年03月23日 14:35:14 +00:00Commented Mar 23, 2023 at 14:35
-
@bjornredemption - I checked /index.php and it is not browsable; it results in 404 page. We use ScandiPWA theme, and it renders /home completely broken. We can't spend time/money fixing the broken rendering. If only we can redirect or just remove /home, our problem is resolved.J Bruni– J Bruni2023年03月26日 23:52:55 +00:00Commented Mar 26, 2023 at 23:52
3 Answers 3
A couple of custom Fastly VCL snippets is what worked for us. (The store is hosted at Adobe's Magento Cloud.)
This configuration can be found at:
- Magento admin > Stores > Configuration > Advanced > System > Full Page Cache > Fastly Configuration > Custom VCL Snippets
The "Redirects" documentation from Fastly helped on creating the specific necessary VCL snippets.
recv
if (req.url.path == "/home") {
error 618 "redirect";
}
error
if (obj.status == 618 && obj.response == "redirect") {
set obj.status = 301;
set obj.http.Location = "https://" + req.http.host + "/";
return (deliver);
}
See the solution at https://fiddle.fastly.dev/fiddle/74577b5a
Here are the screenshots from Magento admin:
IMHO, this is insane. At least, our problem is resolved.
Set a redirect for the "/home" URL: set up a redirect for the "/home" URL to redirect users to the actual home page at "/". To do this, you can create a URL Rewrite in Magento 2.4.4.
In the Magento Admin, go to Marketing > SEO & Search > URL Rewrites, and create a new rewrite.
Set the Request Path to "/home", the Target Path to "/", and the Redirect Type to "Permanent (301)". Save the rewrite and test to see if it redirects users from "/home" to the actual home page.
Let know if you have any query.
Thanks
-
This does not work. As described in the question, this has been attempted, and results in error
Request Path for Specified Store already exists.J Bruni– J Bruni2023年03月21日 18:29:25 +00:00Commented Mar 21, 2023 at 18:29
It seems you want to prevent the home page from being accessible via https://example.com/home, while still keeping it accessible at https://example.com. To achieve this, you can set up a URL redirect using the URL Rewrite Management in Magento 2.
Here's how to create a custom URL Rewrite to redirect https://example.com/home to https://example.com:
Log in to your Magento 2 Admin Panel.
Navigate to Marketing > SEO & Search > URL Rewrites.
Click on the "Add URL Rewrite" button.
Select "Custom" from the "Create URL Rewrite" dropdown menu.
Fill out the form with the following information:
- Store: Choose the appropriate store view.
- Request Path: home
- Target Path: /
- Redirect Type: Permanent (301)
- Description: (optional) Redirect home to root
- Click on the "Save" button to create the URL rewrite rule.
Now, when someone tries to access https://example.com/home, they will be redirected to https://example.com automatically.
Please note that you might need to clear your Magento cache for the changes to take effect:
php bin/magento cache:clean
php bin/magento cache:flush
With this URL Rewrite in place, you can avoid having your home page accessible from the arbitrary URL, and only have it accessible from the root URL.
-
This does not work. As described in the question, this has been attempted, and results in error
Request Path for Specified Store already exists.J Bruni– J Bruni2023年03月21日 18:29:52 +00:00Commented Mar 21, 2023 at 18:29 -
Are you using Nginx ? If so, you may try the following rule :
rewrite ^/home$ https://$http_host permanent;Antoine Martin– Antoine Martin2023年03月21日 22:54:11 +00:00Commented Mar 21, 2023 at 22:54 -
We are using Adobe's Magento Cloud. We don't have access to NginX configuration.J Bruni– J Bruni2023年03月26日 23:56:07 +00:00Commented Mar 26, 2023 at 23:56
Explore related questions
See similar questions with these tags.