htaccess rewrite {rewrite}.html --> {rewrite} - .htaccess

on an onlineshop for years all product pages ended on .html:
www.shop.de/cat/subcat/product.html
now all end without .html:
www.shop.de/cat/subcat/product
I think the shop is indexed via http and https, www.shop.de and shop.de
I need the htaccess rule to strip all urls from .html

This is what did the trick on my server
RewriteEngine on
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule (.+?).html$ /$1 [R=301,NE,NC,L]

Related

Redirect already SEO friendly URL to another SEO friendly URL externally using .htaccess

Part of my .htaccess code is as follows:
RewriteRule ^([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
This basically redirects URL, example.com/XX to example.com/nextlevels_state.php?state=XX and example.com/XX/1 to example.com/nextlevels_state.php?state=XX&page=1 (internally).
Now, I would like to change the URL structure of the URL from example.com/XX to example.com/nextlevels/XX and example.com/XX/1 to example.com/nextlevels/XX/1
and I tried changing .htaccess to as follows:
RewriteRule ^nextlevels/([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
However, as the site urls are already indexed in search engines, I would like to know a way to redirect all the traffic from example.com/XX to example.com/nextlevels/XX (externally) using .htaccess .
Please guide me in this regard. Thank you community :)
Could you please try following, written and tested with shown samples only(improving your already done attempts here). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rule for redirect to url example.com/nextlevels/XX.
RewriteRule ^([A-Z]+)$ nextlevels/$1 [R=301]
RewriteRule ^nextlevels/([A-Z]+)/?$ nextlevels_state.php?state=$1 [NC,L]
##Rule for redirect to url example.com/nextlevels/XX/1.
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels/$1/$2 [R=301]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC,L]

HTACCESS moving pages and masking

I have the current domains
http://domain.com/dev/programme and http://domain.com/dev/software
But I want to point them to http://domain.com/dev/programmes http://domain.com/dev/softwares
I have set up the following htaccess
Redirect 301 /new/programme http://www.domain.com/new/programmes/
Redirect 301 /new/software http://www.domain.com/new/softwares/
This works but the problem comes when you try access sub pages of the main links. The sub pages rely on the slug in the url.
eg. http://domain.com/dev/programme/page and whenever I try access this page with htaccess set like the above it sends me on a redirect loop.
How would I be able to keep the link like http://domain.com/dev/programme/page but have it http://domain.com/dev/programmes whenever its accessed?
Try this:
RewriteEngine On
RewriteRule ^dev/programme$ dev/programmes [L]
RewriteRule ^dev/software$ dev/softwares [L]
RewriteRule ^dev/programme/(.*)$ dev/programmes/$1 [L]
RewriteRule ^dev/software/(.*)$ dev/softwares/$1 [L]
You can do this in a single rewrite rule:
RewriteEngine On
RewriteRule ^(dev/programme|software)(/.*)?$ /$1s$2 [L,NC]

htaccess 301 redirection not working

In my site I want to redirect with http://domain_name.com/blog to http://domain_name.com/news and it should be work with the following criteria also
http://domain_name.com/blog/2012/06/06//blog_title to http://domain_name.com/news
http://domain_name.com/blog/blog/?cat=2 to http://domain_name.com/news
How would I do this?
Can't test that, but anyway...
RewriteEngine on
RewriteRule /
RewriteRule ^/blog/.*$ /news/ [L,R=301]

Trying to do some 301 rewrites but an unwanted urls string is appended

Trying to do some 301 rewrites but an urls string is appended..
I think this is happening because I'm using a SEO rewrite and 301 redirect on top? Any suggestions on how to fix this would be highly appreciated!
The problem is:
This URL: domain.nl/meubels/Tafels/Theetafels-en-wijntafels/
Should be rewritten to: domain.nl/meubels/tafels/theetafel-wijntafel/
But it's rewritten to: domain.nl/meubels/tafels/theetafel-wijntafel/?activetab=Tafels&cat=Theetafels-en-wijntafels
Where this should not be added to the URL: ?activetab=Tafels&cat=Theetafels-en-wijntafels
My htaccess file:
ErrorDocument 404 /error404.php
RewriteRule ^meubels/$ product-listing.php?show=home
RewriteRule meubels/(.*)/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2&open=$3
RewriteRule meubels/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2
RewriteRule product/(.*)/$ product-detail.php?id=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
# DirectoryIndex product-listing.php?cPath=32
Redirect 301 /meubels/Tafels/Theetafels-en-wijntafels/ /meubels/tafels/theetafel-wijntafel/
RewriteRule ^meubels/Tafels/Theetafels-en-wijntafels/ http://domain.nl/meubels/tafels/theetafel-wijntafel/ [R=301,L]
And like #Liam Bailey said, it should be on top, before other rewrite rules.
.htaccess works in vertical order down the page, so if you move your 301 to above the rewrite rules for meubels, then it will redirect and then show the parametised meubels page on the friendly url.
ErrorDocument 404 /error404.php
Redirect 301 /meubels/Tafels/Theetafels-en-wijntafels/ /meubels/tafels/theetafel-wijntafel/
RewriteRule ^meubels/$ product-listing.php?show=home
RewriteRule meubels/(.*)/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2&open=$3
RewriteRule meubels/(.*)/(.*)/$ product-listing.php?activetab=$1&cat=$2
RewriteRule product/(.*)/$ product-detail.php?id=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
RewriteRule info/(.*)/$ text-page.php?show=$1
# DirectoryIndex product-listing.php?cPath=32
The first time it looks at htaccess it will redirect on the 301 straight, then the second time it will skip that and serve the rewrite. If that doesn't work try RewriteEngine On above your rewrite rules.

How to remove a ? from a url with htaccess using 301 redirect

I need an htaccess 301 redirect for dynamic urls going from this url:
http://www.example.com/index.php/?content/page1
to
http://www.example.com/content/page1
My current htaccess rule is:
RewriteBase /
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^index.php(/.*)$ http://%{HTTP_HOST}$1 [R=301]
the problem is I get urls like this:
http://www.example.com/?content/page1
How can I remove that question mark (?) from the url. Also this is for about 20 different urls in this pattern. I would like the rule to work for all my urls needing to be 301 in this pattern.
End the target in a ?.
RewriteRule ^index.php(/.*)$ http://%{HTTP_HOST}$1? [R=301]

Resources