edit parameter with htaccess redirect - .htaccess

Some of the URL's have the parameter ?content_only=1 on the single product pages within PrestaShop. I would like to redirect these parameters to ?content_only=0.
The URL structure looks like this:
https://www.onlineruitershop.nl/paardendekens/3953-esperia-two-fleece-deken.html?content_only=1
This should change to https://www.onlineruitershop.nl/paardendekens/3953-esperia-two-fleece-deken.html?content_only=0
After the first / are the categories and after the second / is the name and ID of the product. This should stay unaffected.
Thanks.

You can try this rule:
RewriteCond %{QUERY_STRING} ^(.*)content_only=1(.*)$
RewriteRule ^(.*)$ /$1?%1content_only=0%2 [L,R=301]
Here is the result

Related

Redirect index.php with parameters to a folder and remove parameters using htaccess

I have searched but cannot find a specific answer for this exact redirect style...
I have this structure of URL with this specific parameter:
https://websitename.com/directory/index.php?option=com_virtuemart&view=cart
I want it redirected to:
https://websitename.com/shopping-cart/
Note that the above mentioned "directory" changes, but the index.php with the parameters stay the same. No matter what the directory is, I always want it to go to the same exact redirect.
I cannot seem to get the right redirect working in htaccess. Can anyone help?
You can use this redirect rule as your first rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?option=com_virtuemart&view=cart [NC]
RewriteRule ^ /shopping-cart/? [L,R=308]
# remaining rules go below this
You can use a set like this. It takes care on the param view=cart
RewriteCond %{QUERY_STRING} (^|&)view=cart
RewriteRule ^(.*)$ /shopping-cart/? [L,NC,R=301]
If you want to keep the querystring params, then change
/shopping-cart/?
to
/shopping-cart/
without questionmark

.htaccess rewrite rule, change URL

I'm looking for the following to change the URL with two variables in a .htaccess file, from:
domain.com/folder/a123/url/index.php
domain.com/otherfolder/a321/url/index.php
to:
domain.com/folder/url/index.php
domain.com/otherfolder/url/index.php
I would prefer it in a single line .htaccess RewriteRule, if possible.
"folder" and "otherfolder" are the only two "folder names" and "a123"/"a321" can be anything starting with "a" and ending with random numbers.
You can do that in one with just one rule using this:
RewriteEngine on
RewriteRule ^(.+)/a[0-9]*/url/index.php$ /$1/url/index.php [R=301,NC]
But if you want to redirect all pages and not only index.php then use this:
RewriteRule ^(.+)/a[0-9]*/url/(.*)$ /$1/url/$2 [R=301,NC]
Also, if you want to rewrite the URLs instead of redirect them change [R=301,NC] to [NC].
Note that if you have that pattern in other URLs this rule will also apply, for example it will also redirect domain.com/adifferentfolder/a567/url/index.php to domain.com/adifferentfolder/url/index.php, if you have those type URLs and don't want to redirect them you need to use two rules instead:
RewriteRule ^folder/a[0-9]*/url/(.*)$ /folder/url/$1 [R=301,NC]
RewriteRule ^otherfolder/a[0-9]*/url/(.*)$ /otherfolder/url/$1 [R=301,NC]

rewriterule for multiple 301 redirects

I've tried looking my question up, but the closest answers I've found didn't work--especially since I'm VERY new to editing .htaccess files.
I have a site that has been programmed to dynamically generate copies of a page to fit a location. For instance, example.com/help/work/ was set up to make about 100 duplicates that look like this: example.com/help/work/?city=Washington&state=DC with the city and state dynamically changing with each page.There are tons of these variations and I want to 301 redirect all the pages with a city and state parameter so they point to the original page (example.com/help/work/).
After some research, I was able to find a RewriteRule that helped me do this on a page by page basis, but only with the homepage:
RewriteCond %{QUERY_STRING} ^city=Philadelphia&state=PA$
RewriteRule ^$ http://example.com/? [R=301,L]
With all that said, I have a two part question:
Is there a way to write this so that it targets subdirectory pages? (I could only get it to do the index)
Is there a way I can use a wildcard like (.*) in a single RewriteRule so example.com/help/work/?city=Washington&state=DC and all its city/state variations point to the original page (example.com/help/work/)?
I'm a bit confused on your request. It appears you want to point every city and state to this single page. http://example.com/help/work/ See if this is what you're looking for.
RewriteCond %{QUERY_STRING} city=.+&state=.+
RewriteRule ^([^/]+)/([^/]+)/?$ http://example.com/$1/$2/? [R=301,L]
Yes, You can use a regex capture group in Rewrite rule that captures the request_uri dynmically .
Like this
RewriteCond %{QUERY_STRING} ^city=.+&state=.+$
RewriteRule ^(.*)$ http://example.com/$1? [R=301,L]

How to redirect URLs that do not contain some specific characters by using htaccess file?

Assume that I have some URL like these:
http://mydomaindotcom/abc/123-link.html
http://mydomaindotcom/abc/page/page-link.html
Now I want to redirect all URLs like : http://mydomaindotcom/otherstring/123-link.html to http://mydomaindotcom/abc/123-link.html
or http://mydomaindotcom/anotherone/page/page-link.html to http://mydomaindotcom/abc/page/page-link.html
It means that the first segment on URL must be [abc], if not, redirect to the [abc]-beginning one.
How can I do this?
Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/abc/ [NC]
RewriteRule ^[^/]+/(.*)$ /abc/$1 [R=301,L,NC,QSA]

i have a problem in .htacces (vanity url)

i am using
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://mywebsite.com/
RewriteRule (.*) http://mywebsite.com//$1 [R=301,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1
it's working , but here my problem is i want my group with vanity url.
right now my user get vanity url like this website[dot]com/username.
But i want my group also with vanity url like website[dot]com/groupname.
can any on help in this?
That would require you to differentiate within htaccess what is a user and what is a group. I don't think that this is an option in your case since (I guess) your user and group names will be dynamic and stored in some kind of DB.
Thus, you'll have to solve the problem in PHP. You could do some rule like this:
RewriteRule ^([a-zA-Z0-9_-]+)$ userOrGroup.php?parameter=$1
and then, userOrGroup.php redirects to either profile.php or groupProfile.php (or whatever your group pages are called), depending on whether the parameter is a user name or a group name.

Resources