I have recently moved a file from one location in my website directory structure to another. Though all the linking has been properly maintained, I see I am getting 404 errors when I attempt to go the old path. I am sure I am having a syntax error but don't know exactly what the problem is.

To be specific.

I want site vistors to automatically be redirected from one location to another when they enter the old URL.

The old URL is:

The new URL is: http://www.homeadditionplus.com/Electrical%20Articles/Ceiling%20Fan%20Wiring.htm

my redirect code is in the .htaccess file is:

redirect http://www.homeadditionplus.com/Electrical%20Articles/Ceiling%20Fan%20Wiring.htm

If you have any ideas on what I am doing wrong please respond.

Thanks,

Mark

Dani AI

Generated

Quick diagnosis and the quick fix. The Apache Redirect (mod_alias) directive expects the old path as an absolute, %-decoded URL-path that begins with a slash — not a full http:// URL — and if the path contains spaces you either quote it or use a rule that understands spaces. was right to point at the path format; 's example shows the right idea. Use mod_alias (Redirect/RedirectMatch) for simple one-to-one moves, or mod_rewrite when you need pattern matching. (httpd.apache.org)

Two practical, safe examples to try (put these in the site root .htaccess). The first is mod_alias (easy). The second uses mod_rewrite so you can escape literal spaces in the match and avoid double-encoding with the NE flag:

# mod_alias (simple)
Redirect 301 "/Ceiling Fan Wiring.htm" "/Electrical%20Articles/Ceiling%20Fan%20Wiring.htm"
# mod_rewrite (pattern match, escape space)
RewriteEngine On
RewriteRule ^Ceiling\ Fan\ Wiring\.htm$ /Electrical%20Articles/Ceiling%20Fan%20Wiring.htm [R=301,L,NE]

Use mod_alias when possible; switch to mod_rewrite if you need regex or complex handling. mod_rewrite matches the %-decoded path, so backslash-escape literal spaces in the pattern. The NE flag prevents Apache from re-escaping percent sequences in the substitution. (stackoverflow.com)

If your redirects still do nothing: confirm the server is reading your .htaccess (a good test is to add an obvious syntax error — if nothing breaks, .htaccess is being ignored), check AllowOverride in the server config, inspect the Apache error log for exact messages, and ensure the .htaccess file is saved without a UTF-8 BOM and uploaded as text (BOMs and wrong encoding commonly produce 500 errors). If your host has FrontPage Server Extensions installed they can overwrite or interfere with .htaccess behavior — ask the host to disable them or manage the redirect for you. (httpd.apache.org)

Notes: ’s JS redirect works only if you can keep the old file; since you must move files out of the root, use server-side 301 redirects for correct behavior and SEO. If you still see problems after the steps above, paste the exact .htaccess snippet (no credentials) and the Apache error-log line — that will pinpoint the issue quickly.

Recommended Answers

All 7 Replies

I have recently moved a file from one location in my website directory structure to another. Though all the linking has been properly maintained, I see I am getting 404 errors when I attempt to go the old path. I am sure I am having a syntax error but don't know exactly what the problem is.

To be specific.

I want site vistors to automatically be redirected from one location to another when they enter the old URL.

The old URL is:

The new URL is: http://www.homeadditionplus.com/Electrical%20Articles/Ceiling%20Fan%20Wiring.htm

my redirect code is in the .htaccess file is:

redirect http://www.homeadditionplus.com/Electrical%20Articles/Ceiling%20Fan%20Wiring.htm

If you have any ideas on what I am doing wrong please respond.

Note I use Frontpage 2003 with frontpage extensions running on an Apache Server.

Thanks,

Mark

Note I use Frontpage 2003 with frontpage extensions running on an Apache Server.

The first argument for the redirect should be a relative path and not a full URL

The first argument for the redirect should be a relative path and not a full URL

I have tried that too to no avail. I think there is something special with Frontpage2003 extensions that is causing the problem.

here is a easy way to get where you want to be with out using htaccess just stick that in the body of the old page and direct it to the new one, not in the head in the body

<script language='javascript'>
var1=8;
var2=var1;
if(var1==var2) document.location="";
</script>

here is a easy way to get where you want to be with out using htaccess just stick that in the body of the old page and direct it to the new one, not in the head in the body

<script language='javascript'>
var1=8;
var2=var1;
if(var1==var2) document.location="";
</script>

Thank you for your input, however I can not keep the old file. The reason for the need to do redirects is that I have too many files in the root directory and my host provider is indicating to me that I have to move some files.

This is taken from my file which works as designed:

Redirect 301 /firstfile.html

//Explaination

'Redirect 301' is the command function
'/firstfile.html' is the old file relative url
'http://www.abcdef.org/nextfile.html' is the url to which
the visitor is being sent

The file holding this instruction is '.htaccess'
Notice the dot preceeding the fine name.


Andy

Thanks,

However I think I have been doing this with no success.

I use the following command in my .htaccess file:

Redirect http://www.homeadditionplus.com/Electrical%20Articles/Ceiling%20Fan%20Wiring.htm

The below old URL is what I am trying to redirect people away from:

The new URL to take its place is:

http://www.homeadditionplus.com/Electrical%20Articles/Ceiling%20Fan%20Wiring.htm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.