Rewrite URL using GET params
I have a URL that looks like this:
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a
I'm trying to get it to look like this:
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]
This code was added to the pub/.htaccess
file.
How do I go about getting the find param into a readable url?
magento2 htaccess
This question has an open bounty worth +100
reputation from treyBake ending in 6 days.
This question has not received enough attention.
add a comment |
I have a URL that looks like this:
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a
I'm trying to get it to look like this:
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]
This code was added to the pub/.htaccess
file.
How do I go about getting the find param into a readable url?
magento2 htaccess
This question has an open bounty worth +100
reputation from treyBake ending in 6 days.
This question has not received enough attention.
Did you make all needed setup related to seo url in admin panel?
– Kirill Korushkin
21 hours ago
@KirillKorushkin not sure I understand - could you please try to clarify? :)
– treyBake
21 hours ago
are you suing nginx or apache?
– Philipp Sander
21 hours ago
@PhilippSander Apache :)
– treyBake
21 hours ago
add a comment |
I have a URL that looks like this:
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a
I'm trying to get it to look like this:
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]
This code was added to the pub/.htaccess
file.
How do I go about getting the find param into a readable url?
magento2 htaccess
I have a URL that looks like this:
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729&sid=T80yDaUX1a
I'm trying to get it to look like this:
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
I found this post on StackOverflow and tried to implement with amendments I though would work, but the page 500s now.
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^*.html/(.*)$ /*.html?url=$1 [L,QSA]
This code was added to the pub/.htaccess
file.
How do I go about getting the find param into a readable url?
magento2 htaccess
magento2 htaccess
edited 22 hours ago
treyBake
asked Jan 18 at 15:02
treyBaketreyBake
187117
187117
This question has an open bounty worth +100
reputation from treyBake ending in 6 days.
This question has not received enough attention.
This question has an open bounty worth +100
reputation from treyBake ending in 6 days.
This question has not received enough attention.
Did you make all needed setup related to seo url in admin panel?
– Kirill Korushkin
21 hours ago
@KirillKorushkin not sure I understand - could you please try to clarify? :)
– treyBake
21 hours ago
are you suing nginx or apache?
– Philipp Sander
21 hours ago
@PhilippSander Apache :)
– treyBake
21 hours ago
add a comment |
Did you make all needed setup related to seo url in admin panel?
– Kirill Korushkin
21 hours ago
@KirillKorushkin not sure I understand - could you please try to clarify? :)
– treyBake
21 hours ago
are you suing nginx or apache?
– Philipp Sander
21 hours ago
@PhilippSander Apache :)
– treyBake
21 hours ago
Did you make all needed setup related to seo url in admin panel?
– Kirill Korushkin
21 hours ago
Did you make all needed setup related to seo url in admin panel?
– Kirill Korushkin
21 hours ago
@KirillKorushkin not sure I understand - could you please try to clarify? :)
– treyBake
21 hours ago
@KirillKorushkin not sure I understand - could you please try to clarify? :)
– treyBake
21 hours ago
are you suing nginx or apache?
– Philipp Sander
21 hours ago
are you suing nginx or apache?
– Philipp Sander
21 hours ago
@PhilippSander Apache :)
– treyBake
21 hours ago
@PhilippSander Apache :)
– treyBake
21 hours ago
add a comment |
2 Answers
2
active
oldest
votes
By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
In your case, you should create a plugin for URL Rewrite router.
I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:
- Create app/code/Vendor/Module/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
- Create app/code/Vendor/Module/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="0.0.1">
</module>
</config>
- Create app/code/Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<type name="MagentoUrlRewriteControllerRouter">
<plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
</type>
</config>
- Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php
<?php
namespace VendorVendorPluginUrlRewriteController;
class Router
{
public function beforeMatch(
MagentoUrlRewriteControllerRouter $subject,
MagentoFrameworkAppRequestInterface $request
) {
$pathInfo = explode('/', $request->getPathInfo());
if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
$realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
$request->setParam('find', $pathInfo[3]);
$request->setPathInfo($realPathInfo);
}
return [$request];
}
}
- Install new module by this command:
php bin/magento setup:upgrade
This module will support to convert the url like
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
to
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/
Hope this will solve your issue
Cheers
add a comment |
Configure URL Rewrites in Magento 2
- On the Admin Panel, Stores > Settings > Configurations.
- In the left panel, under General, select Web.
- Open the Search Engine Optimization section.
- Select "YES"
- Clear configuration cache
source
it's already set to YES
– treyBake
20 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258375%2frewrite-url-using-get-params%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
In your case, you should create a plugin for URL Rewrite router.
I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:
- Create app/code/Vendor/Module/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
- Create app/code/Vendor/Module/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="0.0.1">
</module>
</config>
- Create app/code/Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<type name="MagentoUrlRewriteControllerRouter">
<plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
</type>
</config>
- Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php
<?php
namespace VendorVendorPluginUrlRewriteController;
class Router
{
public function beforeMatch(
MagentoUrlRewriteControllerRouter $subject,
MagentoFrameworkAppRequestInterface $request
) {
$pathInfo = explode('/', $request->getPathInfo());
if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
$realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
$request->setParam('find', $pathInfo[3]);
$request->setPathInfo($realPathInfo);
}
return [$request];
}
}
- Install new module by this command:
php bin/magento setup:upgrade
This module will support to convert the url like
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
to
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/
Hope this will solve your issue
Cheers
add a comment |
By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
In your case, you should create a plugin for URL Rewrite router.
I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:
- Create app/code/Vendor/Module/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
- Create app/code/Vendor/Module/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="0.0.1">
</module>
</config>
- Create app/code/Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<type name="MagentoUrlRewriteControllerRouter">
<plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
</type>
</config>
- Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php
<?php
namespace VendorVendorPluginUrlRewriteController;
class Router
{
public function beforeMatch(
MagentoUrlRewriteControllerRouter $subject,
MagentoFrameworkAppRequestInterface $request
) {
$pathInfo = explode('/', $request->getPathInfo());
if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
$realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
$request->setParam('find', $pathInfo[3]);
$request->setPathInfo($realPathInfo);
}
return [$request];
}
}
- Install new module by this command:
php bin/magento setup:upgrade
This module will support to convert the url like
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
to
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/
Hope this will solve your issue
Cheers
add a comment |
By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
In your case, you should create a plugin for URL Rewrite router.
I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:
- Create app/code/Vendor/Module/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
- Create app/code/Vendor/Module/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="0.0.1">
</module>
</config>
- Create app/code/Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<type name="MagentoUrlRewriteControllerRouter">
<plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
</type>
</config>
- Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php
<?php
namespace VendorVendorPluginUrlRewriteController;
class Router
{
public function beforeMatch(
MagentoUrlRewriteControllerRouter $subject,
MagentoFrameworkAppRequestInterface $request
) {
$pathInfo = explode('/', $request->getPathInfo());
if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
$realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
$request->setParam('find', $pathInfo[3]);
$request->setPathInfo($realPathInfo);
}
return [$request];
}
}
- Install new module by this command:
php bin/magento setup:upgrade
This module will support to convert the url like
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
to
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/
Hope this will solve your issue
Cheers
By default, Magento2 has 4 routers Base > CMS > URL Rewrite > Default
In your case, you should create a plugin for URL Rewrite router.
I can suggest you create a custom module and then create a plugin to solve your issue. You can do as the following steps:
- Create app/code/Vendor/Module/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
- Create app/code/Vendor/Module/etc/module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="0.0.1">
</module>
</config>
- Create app/code/Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<type name="MagentoUrlRewriteControllerRouter">
<plugin name="training_test_rewrite_router" type="VendorModulePluginUrlRewriteControllerRouter"/>
</type>
</config>
- Create app/code/Vendor/Module/Plugin/UrlRewrite/Controller/Router.php
<?php
namespace VendorVendorPluginUrlRewriteController;
class Router
{
public function beforeMatch(
MagentoUrlRewriteControllerRouter $subject,
MagentoFrameworkAppRequestInterface $request
) {
$pathInfo = explode('/', $request->getPathInfo());
if (count($pathInfo) == 5 && !empty($pathInfo[3]) && strpos($pathInfo[2], '.html') === false) {
$realPathInfo = sprintf("%s/%s.html", $pathInfo[1], $pathInfo[2]);
$request->setParam('find', $pathInfo[3]);
$request->setPathInfo($realPathInfo);
}
return [$request];
}
}
- Install new module by this command:
php bin/magento setup:upgrade
This module will support to convert the url like
site.local/wheel-tyres/tyres/aprilia-af-1-futura-1989-4729/
to
site.local/wheel-tyres/tyres.html?find=aprilia-af-1-futura-1989-4729/
Hope this will solve your issue
Cheers
edited 2 hours ago
bachlee89
253
253
answered 2 hours ago
BabonBabon
7328
7328
add a comment |
add a comment |
Configure URL Rewrites in Magento 2
- On the Admin Panel, Stores > Settings > Configurations.
- In the left panel, under General, select Web.
- Open the Search Engine Optimization section.
- Select "YES"
- Clear configuration cache
source
it's already set to YES
– treyBake
20 hours ago
add a comment |
Configure URL Rewrites in Magento 2
- On the Admin Panel, Stores > Settings > Configurations.
- In the left panel, under General, select Web.
- Open the Search Engine Optimization section.
- Select "YES"
- Clear configuration cache
source
it's already set to YES
– treyBake
20 hours ago
add a comment |
Configure URL Rewrites in Magento 2
- On the Admin Panel, Stores > Settings > Configurations.
- In the left panel, under General, select Web.
- Open the Search Engine Optimization section.
- Select "YES"
- Clear configuration cache
source
Configure URL Rewrites in Magento 2
- On the Admin Panel, Stores > Settings > Configurations.
- In the left panel, under General, select Web.
- Open the Search Engine Optimization section.
- Select "YES"
- Clear configuration cache
source
answered 21 hours ago
Philipp SanderPhilipp Sander
4091419
4091419
it's already set to YES
– treyBake
20 hours ago
add a comment |
it's already set to YES
– treyBake
20 hours ago
it's already set to YES
– treyBake
20 hours ago
it's already set to YES
– treyBake
20 hours ago
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258375%2frewrite-url-using-get-params%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you make all needed setup related to seo url in admin panel?
– Kirill Korushkin
21 hours ago
@KirillKorushkin not sure I understand - could you please try to clarify? :)
– treyBake
21 hours ago
are you suing nginx or apache?
– Philipp Sander
21 hours ago
@PhilippSander Apache :)
– treyBake
21 hours ago