Redirect url withouth '/' in Shopware6 - shopware6

How to be solved in a professional way without '/' in url redirecting to page with slash. Currently Shopware 6 has 404 error when is link without slash. I resolved it once in kernel event - response by checking uri path and add slash if uri didn't have it. I do not know if it was the right way.
This is my part of code which I tried to solve a problem:
if (str_ends_with($path, '/') && !$event->getResponse() instanceof StorefrontResponse) {
$response = new RedirectResponse($this->router->generate('frontend.home.page'), 301);
$event->setResponse($response);
return;
}

KernelEvents::REQUEST should fit. Because you might forward the request.
But, there is also a great plugin solving issues with slashes: https://store.shopware.com/en/kielc49617690410/trailing-slash-redirect.html

Related

Heroku PHP app getting 302 error on some links, not others

I'm migrating a working PHP app from my localhost, XAMPP, to Heroku and a few of my links give me a 302 error and the load page says:
"This page isn’t working
mywebsite.heroku.com sent an invalid response.
ERR_INVALID_REDIRECT"
Here is my code for that particular link:
Admin
Here's the code for another broken link that does the same thing:
Login/Register
HOWEVER, here is the code for the link directly beneath that one that works perfectly:
View Cart
Here's the code that has that variable defined.
$web_url = "https://" . $_ENV["HTTP_HOST"] . "/";
EDIT: I've narrowed it down to links that take users to pages where data is entered. It's an ecommerce website so account registration, login, admin login, and checkout where the user enters billing info and credit card.
I think it has to do with the apache server. I do -not- have an .htaccess file so there's nothing in there that would cause this redirect.
Any ideas are appreciated. I am trying to avoid spending a week reading the entire apache documentation.
would suspect the problem to be here...
$app_path = '/' . $dirs[1] . '/' . $dirs[2] . '/';
which should rather be (due to zero-based indexes):
if(sizeof($dirs) == 2) {
$app_path = '/' . $dirs[0] . '/' . $dirs[1] . '/';
}
better rewrite with mod_rewrite, before the request hits any script.
... and when developing on the localhost, xdebug is a good tool.

Google + Redirect URI errors

... When creating Google API if anyone gets an error like this "Invalid Redirect URI". So below I will be posting my solution also that helped me and will save your time.
Trying to find out the mystery about redirect uris myself too but as far as i know you must save the redirect uri you are using in your app into the settings of the api console. Select your project and then clik on the crdentials on the left bar. Yo ucan't miss it

Apache configuring a redirect for 404 behavior to try with .html suffix

I'm looking for a safe way to prevent 404s with smart redirection.
http://www.domain.com/test (results in 404)
http://www.domain.com/test.html (results in page)
Is there a way I can configure Apache to try appending .html to the URL if the page is 404? So basically if I visit: http://www.domain.com/test Apache would say "this page doesn't exist, lets try adding .html suffix to it and see if that exists".
Thanks!
Instead of configuring the apache I reverted to some logic in my application layer for these edge cases.

How to set up the 301 redirect for IIS Server?

i am getting canonical issue in my web site. the error is as follows:
The page with URL "http://dynamicsexchange.com/images/CRMcommunity_supersources_withspaces.jpg" can also be accessed by using URL "http://www.dynamicsexchange.com/images/CRMcommunity_supersources_withspaces.jpg".
all errors i got are related to non-www and www so, please tell me how to set www.mysite.com for my site.
Thanks and Regards
M Prasad Reddy
If it's asp 2 and above you can implement it in 2 ways:
1) ASP.NET: Redirecting with ASP.NET and IIS
you can implement 301 redirects using ISAPI Rewriting modules, products like UrlRewriter.NET which is discussed in Chapter 3, "Provocative SE-Friendly URLs," of the book, Professional Search Engine Optimization with ASP.NET: A Developer's Guide to SEO, or from within your ASP.NET code by setting the appropriate header data.
When using ISAPI_Rewrite, redirecting is implemented similarly to URL rewriting, except that you specify a redirection status code as a parameter.
Example :
The following rule does a 301 redirect to Catalog.aspx when the initial request is for Catalog.html:
301 Redirect Catalog.html to
Catalog.aspx RewriteRule
^/Catalog.html$
http://seoasp/Catalog.aspx [RP]
2) In Code
If you want to implement the redirect yourself, you need to manipulate the response headers using the Response object provided by your current HttpContext object. Here's how to 301 redirect Catalog.html to Catalog.aspx yourself:
if (context.Request.Path == "/Catalog.html")
{
context.Response.Status = "301 Moved Permanently";
context.Response.AddHeader("Location", "http://www.example.com/Catalog.aspx");
}
Explanation: The first URL should be a relative path to the old URL and the second one should be an absolute path to the new URL.

URL Rewrite to remove parameter but send it

I currently use register.php?referal=gamestand on my website so that when the user visits my website through the referal website, I can track how many players have registered from that place.
referal=gamestand will automatically fill in an input textfield within the registration process using echo $_GET['code'];
The problem is... on Google I have loads of links from these referals and I'd like to 301 them to my register.php page to merge the SEO score into one and eventually remove these silly register.php?code=gamestand style links from google.
I've got this rewrite rule... which removes the ?code=gamestand bit, but it doesn't actually pass the parameter, probably because it's redirecting and sending nothing?
RewriteCond %{QUERY_STRING} ^(.*)code(.*)$
RewriteRule ^(.*)$ http://localhost/mywebsite/httpdocs/register.php? [R=301,L]
it will change register.php?code=gamestand into register.php but as I said, $_GET['code'] is now empty and I'm back to square one!
Appreciate any help if anyone knows anything... Thanks! Dom
You could store the referrer in a session variable, then redirect to register.php without the code. Your URL won't contain the code any more, but it's available via the session.
session_start();
if (isset($_GET['code'])) {
$_SESSION['code'] = $_GET['code'];
header('Location: register.php');
exit;
}
...
echo $_SESSION['code'];
Redirecting these Urls to the same Url probably won't merge your SEO score into one. Your current method is fine, don't mess with it.