I could need some help on rewriting the patetrn of the following URL
/folder/subfolder/Product-Name--1235.html
to the URL pattern
/p/product-name/1235
So, the -- needs to be replaced by a / and then added by the number with unknown length.
Any help / info would be appreciated!
You can use the following Redirect :
RewriteEngine on
RewriteRule ^folder/subfolder/(.+?)--([0-9]+)\.html$ /p/$1/$2 [L,R]
The rule above will redirect any URIs of the form /folder/subfolder/foobar--123.html to /p/foobar/123 .
Just put the rule at the top of your root htaccess file.
Related
I am trying to mask the following url with any page number using htaccess.
https://sampledomain.com/?page=2
to
https://sampledomain.com/page/2
So if we call https://sampledomain.com/page/2 url in the website, internally path should always be calling https://sampledomain.com/?page=2 url
Please suggest me the correct htaccess rule.
In htaccess in your document root, use the following rule :
RewriteEngine on
RewriteRule ^page/([0-9]+)/?$ /?page=$1 [QSA,L]
I'd like to setup an htaccess redirect rule which redirects the following pattern:
https://www.example.com/something/ABC123455
to
https://www.new-domain.com/something/ABC123455
while ABC123455 is a dynamic string which can include any upper cased letter and number with exactly 8 characters.
So I guess the regex for this would be:
([A-Z0-9]){8}
So I am looking into several guides:
Redirect to dynamic relative paths with .htaccess?
https://www.sitepoint.com/community/t/htaccess-redirect-with-dynamic-strings/74591
but all I learn is how to setup a route redirect via query parameter ?var=ABC and so on.
Can someone bring me to the right track here? It can't be that hard.
You may use this rule in site root .htaccess of old site:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^something/[A-Z\d]{8}/?$ https://www.new-domain.com/$0 [L,R=301]
I need to redirect based on whether the url contains a string review?review
For example
https://www.example.com/reviews/the-good-diet.1306/review?review=1730#review-1730
should redirect to
https://www.example.com/reviews/the-good-diet.1306/
Another example
https://www.example.com/reviews/the-bad-diet.1417/review?review=1936#review-1936
should redirect to
https://www.example.com/reviews/the-bad-diet.1417/
Can anyone help please
Check this rule on top of your .htaccess file
RewriteEngine On
RewriteBase /
RewriteRule ^reviews\/(.*)\/review(.*)$ /reviews/$1/? [R=301,L]
Redirect dynamic URL for below example :
https://hostname/en/content-page
to
https://hostname/en/storename/content-page
content-page is the dynamic parameters Like-
https://hostname/en/grocery/vegetables?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
to
https://hostname/en/storename/grocery/vegetables?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
OR
http://hostname/en/electronics?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
to
http://hostname/en/storename/electronics?fetchFacets=true#facet:&productBeginIndex:0&facetLimit:&orderBy:&pageView:grid&minPrice:&maxPrice:&pageSize:&
add /storename or /en/storename in dynamic URLs
You should be able to just put /en/ in your pattern and then substitute it with an appended storename. Add this to your .htaccess file:
RewriteEngine On
RewriteRule ^en/(.*)$ https://hostname.com/en/storename/$1 [R=301,L]
That will redirect as you've asked in your examples.
Unfortunately I didn't get it solved by myself and need to ask for help. I want to redirect all urls which follow a certain pattern (in this case it contains "reviews/category"). These URLs supposed to be redirect to another url which is made up the first one:
http://[product-url]/reviews/category/[category-url]
supposed to be redirect to
http://[product-url].html
Furthermore it shouldn't matter if you call the url with or without www.
Example:
http://example.com/ford-blues/reviews/category/cars supposed to be redirect to http://example.com/ford-blues.html
Any help would be much appreciated.
Following code isn't working
RewriteEngine On
RewriteRule ^reviews/category/?$ $1\.html [R=301,L]
Try:
RedirectMatch 301 ^(.*)/reviews/category/ /$1.html
in the htaccess file in your document root.
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^(.*)/reviews/category/ /$1.html [L,R=301]