Moved Category By Mistake and Now URL key has changed - magento

I wanted to move a category called "trinkets" before one called "widgets". Instead, it somehow ended up inside of "widgets." When I moved it back out, the url key was changed to "trinkets-1". How do I get it back to "trinkets"?

Here is something I found - http://www.yireo.com/tutorials/magento/magento-administration/664-fixing-url-rewrites-with-magento
Quoted from the above website:
Sometimes when you make changes to your products, or enable a certain extension, Magento might start to rewrite all your URLs to include a suffix "-1" or some other number. Within the URL Rewrites, Magento differentiates between System URLs and Custom URLs. If the System URLs are broken like this, you should not fix this by adding new Custom URLs.
Instead, open up phpMyAdmin, create a backup of your Magento database, and flush the Magento table core_url_rewrite (so that it becomes totally empty). Immediately afterwards, refresh the Catalog Url Rewrites under Index Management. This will regenerate all System URLs.
If you are comfortable to take a backup and try removing all the records from the above table (obviously preceded by any table pre-fixes), it sounds like a quick fix.

When you rename a category an URL Rewrite Rule is generated so you don't loose the traffic that is incoming on the original category url (see Catalog -> Url Rewrite Management, search for Request Path: trinkets).
Now, when you move it back it checks if the URL Key "trinkets" is already used (which is, because a redirect was generated).
Delete from URL Rewrite Rules the records matching "trinkets" and modift the url key (edit category). Also, when you modify the URL key for the category, make sure the checkbox for " Create Permanent Redirect for old URL" is unchecked.

Related

How do I setup PageRules to bypass Caching against an entire image directory?

I'm working with Cloudflare and one of its benefits is caching. There are certain areas of my site that shouldn't be cached as the results need to be seen by the user. I run an online store and images for products are stored in directories which are also designated by the product Id, this means there are quite a few directories and I don't want the images to be cached.
Here are a few example URLs of product images on my website.
www.mysite.co.uk/images/products/87/image300.jpg
www.mysite.co.uk/images/products/88/image300.jpg
www.mysite.co.uk/images/products/94/image300.jpg
www.mysite.co.uk/images/products/27/image300.jpg
To get around the caching of the above directories I tried adding page rules within the Cloudflare dashboard, despite my best efforts I cannot get Cloudflare to stop caching all the images within the products directory.
My first attempt was to use a wildcard and prevent caching across all pages on my site, the pagerule I used was:
mysite.co.uk/*
However, the above rule didn't seem to do anything. I then attempt to get more granular with it and opted for a rule like this:
mysite.co.uk/images/products/*
This rule didn't seem to work either. I then looked at more advanced wildcard use but I fear I got out of my depth:
mysite.co.uk/images/products/*/$1.jpg
Needless to say, the above rule didn't work either. So, my question is, what rule should I use to prevent caching of my product images?
Assuming your site is published at www.mysite.co.uk and the images you don't want to cache are under www.mysite.co.uk/images/products/... then, you would create a page rule such as:
This rule will tell Cloudflare to not store the resources matching the expression on the CDN. You can also change the rule to match www.mysite.co.uk/images/products/*.jpg if you only want to match jpg images under that folder.
Finally: if there are more page rules defines, it is recommended ordering them from most to least specific, as only one rule is matched for every request.

Magento 2 cannot save category description - modsecurity SQL injection rule

I am working on a Magento 2 project and have been having trouble saving category descriptions.
In the Catalog Save controller action (Magento\Catalog\Controller\Adminhtml\Category\Save), I was logging the request parameters:
$this->getRequest()->getParams()
On most categories all of the request parameters would come through, but certain ones would completely ignore the POST parameters.
After playing around with the description value being posted, I noticed that the request would not come through when my text had an instance of the text select followed later by an instance of from.
My text was something like the following:
"We carry a selection of knives from satin to mirror finish"
I checked the modsecurity logs. It had filtering the requests, mistaking them as SQL injections.
To fix the issue, we add configuration to remove the ModSecurity rules for our specific domains with:
<LocationMatch .*>
SecRuleRemoveById 950004
</LocationMatch>
More on removing ModSecurity rules:
http://www.inmotionhosting.com/support/website/modsecurity/find-and-disable-specific-modsecurity-rules

CodeIgniter router for joomla sef urls?

I wish to create a front-end for joomla using CodeIgniter. I prefer to make my own front-end that reads joomla database and I had my own "framework" to accomplish this, this is because I feel that joomla front-end is too heavy for high traffic websites, because it needs to accommodate for so many user needs, at the end you would really only use a small percentage of what joomla has to offer, yet a lot of unneeded core modules load and when you have a website with 300k visits per day, every bit of resource counts. And I like joomla because of its back-end and database structure.
Anyway, I'm looking to standardize a framework for joomla front-end using CodeIgniter instead of my own messy php code, the main issue for me is the ci router. In joomla I set sef url like these:
websitex.com/
websitex.com/category.html
websitex.com/category/subcat/123-alias.html
I'm looking for a router override that would allow me to process those urls. Basically, if any of the params has a number, then its for sure an article. If it doesn't, and its not index.php then its for sure a category or subcategory (if it exists).
And if I write this:
websitex.com/123 [OR]
websitex.com/category/123-alias.html
It would display the article with id 123. At least that's how it works in joomla and its what I'm trying to achieve here.
If anyone could point me in the right direction that would be great. Thanks in advance.
ADDED:
OK #ImranQamer comment left me thinking. What if I try to do it with conventional CI router? So I tried, and came up with this:
$route['default_controller'] = "controller/index";
$route['index'] = "controller/index";
$route[':num'] = "controller/article";
$route['(:any)/:num'] = "controller/article";
$route['(:any)'] = "controller/section";
I think it may work. I've run some tests and so far so good.
First and second line, if nothing is specified OR index.suffix (index.html) is the URI, then it goes to my controller index method.
Third line, if URI is a number (eg: /123.html) then it routes to controller/article.
Fourth line needs more testing, but apparently it will grab any URI that ends with a number (or number + suffix) and route it to controller/article. Still needs another rule to let article's title alias to be put in the URI (eg: /category/123-hello.html)
And last line, will treat the URI as one of the categories/section of the joomla site. In this controller though, I'm going to need to check if submitted URI corresponds to an existing section, in which case it gets displayed, otherwise, redirected to 404.
I'm gonna test this out for a while, but looks good so far.

Custom profile URL for own site, been though various posts..!

I've been through a few similar posts,
Facebook Like Custom Profile URL PHP
Custom URL / Apache URL Rewriting
But its still not clear, the actual method/process is not available..
Guys , little more guidance would do a lot..
I would like to put forward the questions here:
Users should have a chance to decide what is their url, Just like in case of fb, twitter
for example: www.facebook.com/harry.inaction
I am using the linux, apache, mysql, php environment for this.
Users are identified based on their user id's which get created automatically when they join in
And I fail at the very first step, seriously I don't know get started.
Thanks
It's going to be impossible to put any details as an answer because you've got to build this system of yours and there's more than one way to do it. Design decisions will need to be made based on the way you want things to work and what you already have (they're going to have to work together in some way).
Say you've already got a system for creating users (and it sounds like you do) and you already have a system for viewing profiles. You'll need to extend this system so that you store an extra "my_vanity_url" field in your user table in your database. This field needs to be unique. When a user edits their profile, they have the option of changing this to whatever they want (limiting it to only letters and numbers and dashes for simplicity).
Next, when you display this profile, say it is via /profile.php, your code needs to check a few things.
First it needs to check how it's called, looking at $_SERVER['REQUEST_URI'] you can see either /user/some-vanity-name or /profile.php?u=1234.
If it's the latter, you need to redirect the browser, do a database lookup to see who the user with user_id 1234 is.
Pull the "my_vanity_url" column out of the database for this user and redirect the browser to /user/my_vanity_url_value (replacing my_vanity_url_value with the value of that column).
So now, if you go to http://your.domain.com/profile.php?u=1234, your browser gets redirected and the URL address bar will say http://your.domian.com/user/my_name.
Next, you need to be able to take that unique name and turn it back into the old ugly looking profile page. Two things need to happen here:
You need to extend your profile.php once more to take an optional vanity name as opposed to a user_id
You need to use mod_rewrite to internally route vanity names to /profile.php
For the first thing, you simply look for a different $_GET[] parameter instead of whatever it is for a user_id. Say it's called name: so look at $_GET['name'], see if it exists, if it does lookup the user in the user table whose vanity url name is $_GET['name']. Return the profile of that user.
For the second thing, you just need to put this in the appropriate place in your htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?user/([A-Za-z0-9-]+)/?$ /profile.php?name=$1 [L]
This is just an example for how to implement something like this. It may be completely inapplicable for what you have, but it should give you an idea of what you need to do.

Replacing the "X" in this url www.websitename.com/info.php?lid=X

Help please.
I am looking for the best way to replace the "X" (number) in this url
www.websitename.com/info.php?lid=x
the "x" is a numerical value - i would like to replace the "X" with the "name" field from my database.
Is mod rewrite the way to go? I have multiple urls of the same format (different "X" value of course at the end) that i wish to change to create more friendly urls by replacing the "X" with the corresponding value from the database field "name".
If mod rewrite is the way to go can anyone help out with recommended code to go in the htaccess?
Thanks in advance.
Totally edited: My previous answer was based on a misunderstanding of what you're trying to ask.
What you are asking is to create a friendly URL system. This is covered in many tutorials -- just search for "friendly URLs" and you'll find lots of resources.
Here's a summary of how it works...
To create friendly URLs for your site, you would need something like this in .htaccess (not sure if I got the RewriteRule right because this is completely off the top of my head, so google for a full-blown tutorial to verify):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule /info/(.+) /info.php?name=$1
</IfModule>
This means a request to http://www.example.com/info/foo would be rewritten to http://www.example.com/info.php?name=foo.
Then you need to modify your application (in particular, the info.php file) to handle this new request format in which the name is given in the URL instead of the id.
Note that in this example, all names (e.g., "foo") must be unique. If any two items in your database have the same name, you're going to have problems. With this in mind, you might want to add a new field to your database table, which is a unique column containing a string using only alphanumeric characters and hyphens appropriate for use in a URL (this type of string is called a slug). You will basically use this slug instead of the id for database queries. Let's say you create an item named "The Discombobulator". When this item is created in your application, it should also create a slug along the lines of "the-discombobulator" and ensure it's unique. If you create a second item also called "The Discombobulator", your app might generate a slug for it like "the-discombobulator-2".
So, when someone requests http://www.example.com/info/the-discombobulator-2, mod_rewrite changes that to http://www.example.com/info.php?name=the-discombobulator-2 and hands it to your app. Your app gets the name parameter, which is "the-discombobulator-2" and looks that up in the database's slug field, and gets the matching record.
I think this is what you are looking for:
http://www.roscripts.com/Pretty_URLs_-_a_guide_to_URL_rewriting-168.html

Resources