Why is my Htaccess redirect not working on Apache server?

  • Thread starter Thread starter CRGreathouse
  • Start date Start date
  • Tags Tags
    apache
Click For Summary
SUMMARY

The forum discussion centers on issues with implementing redirects on an Apache server using the .htaccess file and httpd.conf. Users reported that standard Redirect directives, including "Redirect permanent" and "Redirect 301," failed to work as expected, resulting in the original file being served instead of the intended target. The discussion highlights the importance of ensuring the alias_module is loaded and suggests using the RedirectMatch directive with regular expressions as a potential solution for more complex redirect scenarios.

PREREQUISITES
  • Understanding of Apache server configuration
  • Familiarity with .htaccess file syntax
  • Knowledge of Redirect and RedirectMatch directives
  • Basic understanding of regular expressions
NEXT STEPS
  • Research "Apache RedirectMatch syntax and usage"
  • Explore "Apache mod_rewrite for advanced URL manipulation"
  • Learn about "Apache server configuration best practices"
  • Investigate "Common issues with .htaccess file directives"
USEFUL FOR

Web developers, system administrators, and anyone configuring URL redirects on Apache servers will benefit from this discussion.

CRGreathouse
Science Advisor
Homework Helper
Messages
2,832
Reaction score
0
I'm running an Apache server, but I'm having trouble redirecting files. I've tried including lines like

Code:
Redirect permanent /oes.htm [PLAIN]https://example.com/file.html[/PLAIN]
[/URL]

in the httpd.conf file as well as in an .htaccess file, but loading the URL in the browser I only get the original file, not the file I'm redirecting to. Neither of

Code:
Redirect /oes.htm [PLAIN]https://example.com/file.html[/PLAIN] 
Redirect 301 /oes.htm [PLAIN]https://example.com/file.html[/PLAIN]
[/URL]

work (though all three should be the same, I think, unless Redirect gives a 302 instead).


I'm including alias_module already:
Code:
LoadModule alias_module modules/mod_alias.so

What am I doing wrong? Is there something else I need to configure?
 
Last edited by a moderator:
Computer science news on Phys.org
Here is an example of what PF does for it's blogs. Top of the htaccess file.

Code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) [PLAIN]https://www.physicsforums.com/blog.php$1[/PLAIN]  [R=301,L]
 
Last edited:
I remember that getting the Redirect directive to work was a pain in the butt, and I ended up having to use RedirectMatch instead, but I don't remember exactly why... try this instead maybe?
Code:
RedirectMatch \/oes.htm$ [PLAIN]https://example.com/file.html
[/PLAIN]
The first parameter is a regex, of course, with the slash escaped and "$" signifying end-of-string.
 
Last edited by a moderator:

Similar threads

  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 15 ·
Replies
15
Views
8K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 152 ·
6
Replies
152
Views
12K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
6K