i look for a redirect pattern which redirects all URLs with the slug /at/ to the frontpage of my site.
example:
https://www.example.com/at/shop/systeme/alf/product.html
should redirect to:
https://www.example.com/de/shop/ (this is my frontpage)
i have hundrets of urls with /at/ in the slug. All these Urls should redirect (301) to
https://www.example.com/de/shop/
i hope somebody can help me
best regards
Tom
This probably is what you are looking for:
RewriteEngine on
RewriteRule ^/?at/ /de/shop/ [R=301,QSD]
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This rule will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
Related
could you please help me with a 301 redirect rule, so that all URLs
https://example.com/sub/sub/category/sub
are redirected to
https://example.com/sub/sub/sub
I need to remove "category" subfolder from all URLs, but the rule should be independent of "sub" name.
Thanks!
Sounds pretty straight forward:
RewriteEngine on
RewriteRule ^/?/([^/]+)/([^/]+)/[^/]+/(.+)$ /$1/$2/$3 [QSA,R=301,END]
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This implementation will work likewise in the http servers host configuration or inside a distributed configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a distributed configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using distributed configuration files (".htaccess"). Those distributed configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
I updated my website, and I'm attempting to make sure a bunch of old URLs redirect to the correct page. Some of my links are working fine, while others aren't.
Example:
Redirect 301 /compare-suites/ /en/our-products/compare-suites
Redirect 301 /compare-suites/?lang=fr /fr/nos-produits/comparaison-des-suites/
The first redirect works perfectly, but the second one redirects to /en/our-products/compare-suites?lang=fr, ignoring my second rule.
The alias module which offers the Redirect directive is unable to handle the query string inside a URL. That is clearly stated in the documentation. Along with the hint to use the rewriting module instead.
I strongly recommend that you start reading the documentation of the utilities you use:
Alias module: https://httpd.apache.org/docs/current/mod/mod_alias.html
Rewrite Module: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
As typical for OpenSource they are of excellent quality and come with great examples.
This would be the approach you are probably looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)lang=fr(&|$)
RewriteRule ^/?compare-suites/?$ /fr/nos-produits/comparaison-des-suites/ [QSD,R=301,END]
RewriteRule ^/?compare-suites/?$ /en/our-products/compare-suites [R=301,END]
Note that the more specialized exception has to be implemented before the more general fallback, so further up in the configuration file.
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This implementation will work likewise in the http servers host configuration or inside a distributed configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a distributed configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using distributed configuration files (".htaccess"). Those distributed configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
I am trying to 301 redirect some url from my old site structure to my new simpler site structure.
My original urls are formatted: /my-place-name-33/ for example, which I need to redirect to just /my-place-name/ completely omitting the -33
I tired adapting the solution from this thread: htaccess - 301 redirect removing part of url but my separator isn't strong enough (if that makes sense). I only have a hyphen to separate, but in most cases on the site, the my-place-name already contains hyphens.
I'm pulling my hair out trying to get around this. Any help would be amazing.
Many thanks
D
I'd say that this simple approch should do what you are looking for:
RewriteEngine on
RewriteRule ^/?(.+)-\d+/?$ /$1/ [END]
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This rule will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
I want to redirect one of the main pages of mysite with its sub pages.
My current URL;
www.mysite.com/article/service-1
www.mysite.com/article/service-2
I want to redirect to;
www.mysite.com/publication/service-1
www.mysite.com/publication/service-2
How can I redirect so?
Your question is a big vague as to what you actually try to achieve. So I will give you two answers as a starting point:
I assume you actually want an internal rewrite, not a rediretion. If so this will do:
RewriteEngine on
RewriteRule ^/?article/(.*)$ /publication/$1 [END,QSA]
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
If you really want a redirection as you write in your question, then this variant will do, it will actually redirect the client, so change the visible URL in the browser:
RewriteEngine on
RewriteRule ^/?article/(.*)$ /publication/$1 [R=301,QSA]
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
Both rules will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
URL /%variable1%/plan/%variable2%/ need redirect to /%variable1%/
I tried:
RewriteRule ^([^/]+)/?(.*) /$1/plan/$2 [L]
Returns a 500 error
Please tell me how to do it in Apache
Your question is a bit vague, but this should do what you actually ask:
RewriteEngine on
RewriteRule ^/?([^/]+)/plan/[^/]+/?$ /$1/ [R=301,END]
I am not convinced though that this is what you really want to achieve, since it is uncommon and you will actually lose the information held in what you referred to as "variable2".
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This rule will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).