How to erase part of the link using .htaccess - .htaccess

i change the permalink of wordpress with the rule "/%postname%/" and it's working perfectly.
The only problem i use wp-commerce and for some reason generate the permalink to the product with this in the end "&negozio=NEGOZIO" and so give for every product i want to see a 404 page.
I know with .htaccess you can rewrite urls so i'm asking what's the correct rule for make a link like this :
http://www.ctssolutions.it/products-page/gestione-banconote/bj-140/&negozio=NEGOZIO
became something like this :
http://www.ctssolutions.it/products-page/gestione-banconote/bj-140/
Thank in advance

Related

Redirect issues: New category/article structure / How to get rid of the article id?

I guess, this is an easy one but anyway, I haven't figured it out yet.
After migrating my website from Joomla 3 to Joomla 4 the structure of categories and articles will change. That's why I will need some rules in .htaccess to redirect the old urls to the new ones.
The website is hosted on an Apache server.
The old URL structure looks something like that.
https://www.mydomain.de/category/subcategory/item/[articleID]-[articleAlias].html
[articleID] is a digit.
[articleAlias], e.g. „this-is-article-number-233“
This should be redirected to...
https://www.mydomain.de/newcategory/newsubcategory/[articleAlias].html
An example:
https://www.mydomain.de/category/subcategory/item/2324-this-is-my-latest-article.html
… should be redirected to...
https://www.mydomain.de/newcategory/newsubcategory/this-is-my-latest-article.html
I've played around with RedirectMatch and Rewrite Rule but haven't been successful to make it work. How do I get rid of the article id?
My latest try failed with...
RedirectMatch ^category/subcategory/item/([0-9]+)-(.*)$ /newcategory/newsubcategory/$1
Is there a simple and elegant solution to this? Thanks in advance!
UPDATE
Maybe it's more complex than I thought it was.
Main problem is that not only my categories changed but also the ids of the articles.
So, to stick with my example...
https://www.mydomain.de/category/subcategory/item/2324-this-is-my-latest-article.html
first turns into something like:
https://www.mydomain.de/newcategory/newsubcategory/1223-this-is-my-latest-article.html
Anyway, Joomla 4 is able to drop the article id automatically (guess with an internal rewrite) for seo-friendly URLs. I activated that feature to make the new URLs look like
https://www.mydomain.de/newcategory/newsubcategory/[articleAlias].html
The [articleAlias] stays the same.
A redirection according to what you actually ask should be possible like that:
RewriteEngine on
RedirectRule ^/?category/subcategory/item/[0-9]+-(.*)\.html$ /newcategory/newsubcategory/$1.html [R,L]
However I doubt that this really is what you want: this completely drops the numeric ID of the resource. Which means that it won't be available for processing when the redirected request comes back requesting the new, stripped URL. How do you want to internally rewrite that request back to the internal resource then, without that ID?
I made some more tests and it this is the final solution to my problem:
RedirectMatch 301 ^/?category/subcategory/item/[0-9]+-(.*)\.html$ /newcategory/newsubcategory/$1.html

.htaccess rewrite url that has already been changed

I am upgrading my site which involves new scripts and a different URL
structure. There are currently a few thousand pages so I want to
basically move them in to a subdirectory so that they are not lost.
I am not very confident with htaccess so can someone please confirm that
the first part I have done is correct:
Old URL: http://www.example.com/article/another-dir/page-group/whatever.html
RewriteRule ^article/?$ http://www.example.com/archive/ [R=301,NC,L]
To achieve this: http://www.example.com/archive/another-dir/page-group/whatever.html
Search engines will see the above as a permanent move and in the address bar
it will show the new url. Is this right?
The second part is on the new script - the url's could be improved but I am
unable to change all the script so thought about using htaccess again but am
not sure if it can be achieved like this.
At the moment the url looks like this:
url: http://www.example.com/category/4/categoryname
In the htaccess the current rewrite rule for this type of url looks like this:
RewriteRule ^category/(.*)/(.*)$ category.php?id=$1&slug=$2
Is it possible to change this so that in the url address bar I end up
with this:
http://www.example.com/categoryname
Basically I don't want to see either the number or category/ in the resulting
url as it will be easier for visitors to use - is that possible??
Thanks in advance for any help.
The second question related to passing in URI components for querystring redirect and then hiding those components in the URL I don't think would be easy, if even possible, using RewriteRules.
For the first question though. Given the sample URLs you mentioned, the RewriteRule would need to include capture and backreference if you want to preserve the full URL in the redirection. For example:
RewriteRule ^article/?(.*)$ http://www.example.com/archive/$1 [R=301,NC,L]

Old link structure to new url structure

We have our own CMS, and having some vacancies website's. Now the issue is, for SEO we've changed the page, where the vacacies are showed on, now google says 300 vacancies can't be found.
I'm asking for your help, since i dont want to changes 300 urls handy..
What i have here is the next url :
website.html/vacatures/vacancieitem/289-docent-duits-1e-graad.html
website.html/vacatures/vacancieitem/245-docent-wiskunde-1e-graad.html
Needs to go to the new url
website.html/onderwijsvacatures/vacancieitem/289-docent-duits-1e-graad.html
website.html/onderwijsvacatures/onderwijsvacatures/245-docent-wiskunde-1e-graad.html
and so go onn
You can use the following redirect in your htaccess :
Redirect 301 /vacatures/ /onderwijsvacatures/

How to remove (not hide) a subdirectory from a URL using .htacesss

I have a series of URLs on my website:
http://www.example.com/sub1/sub2/content.html
But I would like to remove "sub1" completely - not hide it so it still attempts to access that directory. Finished result would be this URL:
http://www.example.com/sub2/content.html
Many similar posts on SE seem to demonstrate how to "hide" a URL from the user. I want to rewrite the URL so that it treats it as if it isn't even there.
Example of what I'm trying not to do: Hide Part of URL htaccess
NOTE: I do not want to actually delete files as suggested by the comment below. I'm trying to redirect the request to another directory.
This worked for me:
RewriteRule ^sub1/sub2/(.*)$ /sub2/$1 [R=302,NC,L]
Helpful page: http://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/

links includes coma and hash htaccess

I'm using links like that:
find.php?id=1&n=2#loc
I want to my links look like:
but i dont know how to change htaccess and when/where use # to link some place in the page #loc
htaccess:
RewriteRule ^(.*),(.*),(.*)$ $3.php?id=$2&n=$1 [L,NC,NS,NE]
Help lease
The #loc part of the URL is never sent to the server, so there's no way for you to match against it in your htaccess file. Anything starting from the # in the URL is called a fragment and it's used by the browser, the server doesn't know it's even there.

Resources