Htaccess - Where is the error - .htaccess

I am not able to find the error in the following Htaccess Code.
Isn't it just a simple 301 redirection?
Redirect 301 flaechenformeln.html http://www.mathespass.at/formeln/flaechenformeln.php
I have also tried to change the redirect a bit, but it is not working.
But however this works:
Redirect 301 /testversion/klasse2/index.html http://www.mathespass.at/testversion/klasse2/index.php
Isn't it the same?
Hope you can help me!
With best greetings

Redirect directive performs starting string match of the REQUEST_URI with the given pattern and it must start with a /.
Try this rule instead:
Redirect 301 /flaechenformeln.html http://www.mathespass.at/formeln/flaechenformeln.php

Related

Rewrite Rule For Base Directory

So I'm trying to rewrite the following example. Took a look around but couldn't find the correct post that matched this scenario.
Here is a list of layout for old pages:
www.url.com/directory
www.url.com/directory/page1.html
www.url.com/directory/page2.php
I'm trying to rewrite the following way through htaccess:
Redirect 301 /directory /newdirectory
Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2
However, the first rewrite rule is interfering with old subpages in that path. So for example, using the above rewrite rules, going to:
www.url.com/directory/page1.html
Points the user to:
www.url.com/newdirectory/page1.html
When it should be pointing user to the slug without the original filename extension:
www.url.com/newdirectory/page1
The only way around this that I've been able to manage is to leave out the www.url.com/newdirectory/page1.html rule entirely. But there are a bunch of links pointing to that base path, so I'd like to redirect that.
Any help would be greatly appreciated. Thanks in advance for the time and help.
url-rewriting redirect rewrite-rules
You need to place the rule for the base directory after the ones for the subpages :
Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2
Redirect 301 /directory /newdirectory

URL rewrites issues

We are having a problem with URL rewrites on an apache server using .htaccess.
Goal: to have the following URL stripped of its category & subcategory while leaving the generic redirect in place.
Test 1:
Redirect 301 /category/subcategory/product http://www.site.com/product
Redirect works perfectly. A single redirect to the desired page.
Test 2:
RedirectMatch 301 ^/category/subcategory/.*$ http://www.site.com/category/subcategory
Redirect on its own works perfectly for all URLs desired.
The problem is when we have both URLs in a clean .htaccess file, and the redirects are in the proper order (specific first, then general), the general redirect is being used.
Test 3:
Redirect 301 /category/subcategory/product http://www.site.com/product
RedirectMatch 301 ^/category/subcategory/.*$ http://www.site.com/category/subcategory
When we visit www.site.com/category/subcategory/product, the result is www.site.com/category/subcategory/product, That is not the desired result. Instead, we want the URL to be www.site.com/category/subcategory/product,
We have even tried modified the Redirect to:
Redirect 301 /category/subcategory/product http://www.site.com/product [L]
It made no difference.
Please help!
EDIT: Added 3/25/2014
What we are trying to do is provide specific redirects for a group of known products from their old product page to the new product page. We are also trying to add a "catch all" redirect for the remaining unknown products to the category page.
Here is an actual example redirect which works:
Redirect 301 /womens/western-dresses/stetson-cream-empire-waist-ls-western-dress http://www.site.com/stetson-cream-empire-waist-ls-western-dress
If the above redirect is added to the .htaccess file, it works perfectly on its own.
Here is a second example redirect which works:
RedirectMatch 301 ^/womens/western-dresses/.*$ http://www.site.com/womens/western-dresses
The problem is if we have both of the rules together in .htaccess, in the same order as above, the second rule is always triggered. We try to access www.site.com/womens/western-dresses/stetson-cream-empire-waist-ls-western-dress and the result is www.site.com/womens/western-dresses instead of the desired result of www.site.com/stetson-cream-empire-waist-ls-western-dress
For clarity:
if we remove the .htaccess file, the URL 404s
if only the first rule is listed, it triggers perfectly
if only the second rule is listed, the second rule triggers perfectly
if both rules are listed, the second rule triggers.
We have deleted all redirects from the .htaccess file. The only redirects are the below two lines. The issue remains where the first redirect is ignored. We have tried changing the start of the first redirect to ^/womens and ^womens but that change had no effect.
Redirect 301 /womens/western-dresses/stetson-cream-empire-waist-ls-western-dress http://www.site.com/stetson-cream-empire-waist-ls-western-dress
RedirectMatch 301 ^/womens/western-dresses/.*$ http://www.site.com/womens/western-dresses
Your post is a little confusing, so I may be misunderstanding what you are trying to do.
If memory serves, you should not include a leading slash in your pattern when using these directives in a .htaccess file. That usage is reserved for httpd.conf. When these directives are used in a .htaccess file, the leading path components have already been stripped by mod_access. I am guessing this is the cause of your troubles.
For example, this should work (not tested):
Redirect 301 ^category/subcategory/product http://www.site.com/product
RedirectMatch 301 ^category/subcategory/.* http://www.site.com/category/subcategory
As an aside, [L] is mod_rewrite lingo. "Redirect" and "RedirectMatch" are part of mod_access.
EDIT 3/25:
Redirect and RedirectMatch can be fussy when used in .htaccess files, particularly when dealing with non-existent folders and mixed directives. Can I suggest you move directly to mod_rewrite? While it has a steep learning curve, you will never go back once you get the hang of it.
# Assuming you are in a .htaccess under DocumentRoot:
RewriteEngine On
RewriteRule ^category/subcategory/product1\.html$ /product1.html [R=301,L]
RewriteRule ^category/subcategory/product2\.html$ /product2.html [R=301,L]
RewriteRule ^category/subcategory/.* /category/subcategory [R=301,L]
As an aside, this looks like a good candidate for RewriteMap, although you will need to declare the map in your httpd.conf.

301 permanent redirect not working in htaccess

we are facing urls like "http://domain.com/p/post-content/%3Ca%20href=", these urls generate 404 errors, when we have tried to redirect something like that
Redirect 301 /p/post-title/<a href= /p/post-title/
But its not working, please anybody let me know, how to redirect url like this
The extra space is messing up the statement, apache will think there are too many arguments. Try:
Redirect 301 "/p/post-title/<a href=" /p/post-title/

301 redirect for wordpress permalink

on .httaccess, we use like this.
RedirectMatch 301 ^/food/(.*)$ http//:domain.com/food-for-healthy/$1
It works well. but we have a problem with 1 old link. we used to have a multi-site and the name is "food". it was changed to "food-for-healthy". Therefore we have changed like so:
RedirectMatch 301 ^/food/(.*)$ http//:domain.com/food-for-healthy/$1
and as you know, http//:domain.com/food/ and http//:domain.com/food are the same.
The problem is http//:domain.com/food which needs to go to http//:domain.com/food-for-healty/
I have tried several things but my attempts produce a redirect error.
RedirectMatch 301 /food http//:domain.com/food-for-healthy
this gets a redirect error. how can I change it to work properly?
I have tried this..
RedirectMatch 301 ^/food/?(.*)$ http//:domain.com/food-for-healthy/$1
but
it comes with a redirect error and goes to
http:/:domain.com/food-for-healthy/food-for-healthy/food-for-healthy/food-for-h‌​ealthy/food-for-healthy/food-for-healthy/food-for-healthy/food-for-healthy/...
There's no reason I can see why RedirectMatch is required since you're doing a simple redirect from one place to another and aren't dealing with additional query string values or sub-pages (that you've said).
Redirect permanent /food/ http://domain.com/food-for-healthy/

.htaccess Redict 301: Stop Redirection for Subfolders

Hello and thank you for being there,
I'm trying to redirect the page www.mydomain.com/hello/page to www.mydomain.com/mypage
I'm using this rule
Redirect 301 /hello/page http://www.mydomain.com/mypage
It works fine, but the problem comes now with pages like www.mydomain.com/hello/page/page2
They are automatically redirected to www.mydomain.com/mypage/page2
Is there a way I can redirect all pages that go to /hello/page/(whatever) to www.mydomain.com/mypage instead of www.mydomain.com/mypage/(whatever)
Thank you very much!
So I found a way to do it in case someone runs into the same question:
redirectMatch 301 ^/hello/page/(.*)$ http://www.mydomain.com/mypage
Hope it help.

Resources