|Redirect rule does not work|
| 12:41 pm on Aug 27, 2013 (gmt 0)|
I'm quite new to writing apache rewrite rules.
I have a server with multiple sites on, and only one .htaccess
I'm trying to write a simple redirect rule within a single domain.
This is what I already have and it is working
RewriteRule ^/(.*)$ http://www.example.com/our_business/plastics/pvc-vcm/ [R=301]
What I'm trying to do is redirect everything from "www.example.net/tece" to "www.example.net/some_new_path/"
This is what I have and it is not working
RewriteRule ^/tece$ http://www.example.net/some_new_path/ [R=301]
I have tried numerous regexes, but nothing seems to work. This is only a sample of tried regexes:
"^/$" www.example.net/ going to this address does not trigger the redirect also
Out of desperation I have even tried without starting "/" but nothing I try seems to work. I've checked everything with fiddler and all other redirects I wrote work but this one. It seems like Apache does not even come to the lines where redirect is.
Any ideas on why is this not working? Is there a way to prevent redirects for a certain domain(maybe on some other level), as I'm not the only one that has been working on this server so there might be some other config somewhere, but there is only one .htaccess file, I've checked it.
When trying to go to that URL fiddler and browsers show me 404, and this is what I would expect because there is nothing there, but it does not even try to redirect as far as I can see.
Thanks for all ideas and help in advance!
[edited by: Ocean10000 at 2:03 pm (utc) on Aug 27, 2013]
[edit reason] Examplified [/edit]
| 7:09 pm on Aug 27, 2013 (gmt 0)|
Tangential question first:
|I have a server with multiple sites on, and only one .htaccess |
Is ".htaccess" a simple typo for "config file" OR is there a single htaccess in one location in addition to the config file OR is all the quoted content in an htaccess file? (I really hope not, since you're quoting config-only material.)
|What I'm trying to do is redirect everything from "www.example.net/tece" |
Does "everything from" mean all URLs beginning in "www.example.net/tece" or does it mean the one specific URL "www.example.net/tece"? Based on the prose I'd assume "beginning in", but all forms of the Regular Expression have an ending anchor, meaning "exact (extensionless) URL".
The Regular Expression
only and nothing else.
| 7:36 pm on Aug 27, 2013 (gmt 0)|
As Lucy24 said, it looks like you're working in the httpd.conf not the .htaccess. If that's not the case you'll need to remove the / from the left side of the rule since it's not present in the .htaccess, otherwise it looks like some of what you've tried should work, which makes me wonder if you rebooted the server and emptied your cache prior to testing?
RewriteRule ^/tece(.*)$ http://www.example.com/our_business/plastics/pvc-vcm/$1 [R=301,L]
I made a couple of adjustments to one of your test rules, but what you had appears like it should have worked to redirect even though there were a couple of details missing.
I added tece to match the correct directory, the $1 back-reference to the right side for a page-to-page redirect and also the L flag, which should always be used unless you know exactly why you don't want it.
| 7:48 pm on Aug 27, 2013 (gmt 0)|
if this is actually in .htaccess, the VirtualHost container won't work in that context and its contents are probably being ignored.
| 10:44 pm on Aug 27, 2013 (gmt 0)|
I suspect that when the OP said
he really meant
But this is only an issue if there exist other top-level directories called teceblahblah with additional text. (tece-blahblah would still pass, because \b includes hyphens.)
Either way it won't work if you need to preserve the rest of the request. You could do it in RedirectMatch-- but if you're new to this whole server thing, you're better off not mixing mod_alias (Redirect by that name) and mod_rewrite.
| 9:55 am on Aug 28, 2013 (gmt 0)|
I'm working together with IcepickD on same problem, he is not able to answer your questions this week.
First, IcepickD made one mistake, rewrite rules aren't defined in .htaccess file but in httpd.conf file (more precisely in another config file (eg. xyz.cong) which is included in httpd.conf).
@lucy24 asked what "everything from" means:
It means everything that begins with "www.example.net/tece"
@JD_Toims, I have tried your rewrite rule but it won't work :(
Could it be that the fact that '/tece' folder doesn't exist makes a problem?
Also, maybe it is important to know that there is a redirection in root folder index.jsp page:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
This redirection redirects all "www.example.com" requests to "www.example.com/fr/index.jsp". Could it be that this is messing with redirect rulles defined in Apache's confs files?
| 10:18 am on Aug 28, 2013 (gmt 0)|
|Could it be that the fact that '/tece' folder doesn't exist makes a problem? |
You mean the physical directory is no longer there, it's just a part of the URL? No, in most situations that would have no effect. After all, the whole reason for the redirect is to intercept requests before they get a chance to find out whether the original target exists or not.
Does JD's suggested rule work if you leave off the opening anchor? If the rule is lying loose in the config file, rather than inside a <Directory> section, there's no telling what the path really looks like. (That is: Someone who knows your server and speaks Apache can tell, but I can't.) So try it without anchors.
|This redirection redirects all "www.example.com" requests to "www.example.com/fr/index.jsp". |
If this is happening within one specific page, then it can't affect any requests that don't reach that page.