Why is my Htaccess redirect not working on Apache server?

  • Thread starter CRGreathouse
  • Start date
  • Tags
    apache
In summary, an Htaccess redirect may not be working on an Apache server due to several reasons such as incorrect syntax, conflicting directives, or server configuration issues. It is important to carefully check the code and troubleshoot any errors to ensure the redirect is properly set up and functioning correctly. Additionally, caching and browser issues can also cause problems with redirects. Regular maintenance and testing can help prevent and resolve any issues with Htaccess redirects on an Apache server.
  • #1
CRGreathouse
Science Advisor
Homework Helper
2,844
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
  • #2
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:
  • #3
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:

Related to Why is my Htaccess redirect not working on Apache server?

1. What is an htaccess redirect on Apache?

An htaccess redirect on Apache is a feature that allows you to redirect website visitors from one URL to another. This can be useful for various reasons, such as changing the URL of a page or directing visitors to a new version of your website.

2. How do I create an htaccess redirect on Apache?

To create an htaccess redirect on Apache, you will need to use the RewriteEngine and RewriteRule directives in your .htaccess file. These directives allow you to specify the URL you want to redirect from and the URL you want to redirect to.

3. Can I use regular expressions in my htaccess redirects on Apache?

Yes, you can use regular expressions in your htaccess redirects on Apache. This allows you to create more complex redirects and redirect multiple URLs at once.

4. How do I test if my htaccess redirects on Apache are working?

To test if your htaccess redirects on Apache are working, you can use a web browser or a tool like htaccess tester. Simply enter the URL you want to redirect from and the URL you want to redirect to, and the tool will show you if the redirect is working correctly.

5. Are there any risks associated with using htaccess redirects on Apache?

There are some potential risks when using htaccess redirects on Apache. For example, if you make a mistake in your redirect rules, it could cause your website to break or redirect to the wrong URL. It is important to test your redirects thoroughly and make backups of your .htaccess file before making any changes.

Similar threads

  • Computing and Technology
Replies
4
Views
3K
  • Programming and Computer Science
Replies
15
Views
7K
  • Programming and Computer Science
Replies
6
Views
2K
Replies
152
Views
5K
  • Computing and Technology
Replies
10
Views
3K
  • General Math
Replies
3
Views
5K
  • Computing and Technology
Replies
4
Views
3K
  • Feedback and Announcements
Replies
0
Views
94K
Replies
22
Views
2K
Replies
6
Views
2K
Back
Top