Htaccess redirects on Apache

  • Thread starter CRGreathouse
  • Start date
  • Tags
    apache
In summary, the individual is having trouble redirecting files on their Apache server. They have tried various methods, including using the Redirect directive in the httpd.conf file and .htaccess file, but none have been successful. They are also already including the alias_module. They are unsure of what they are doing wrong and are wondering if there is something else they need to configure. Another user suggests using the RedirectMatch directive with a regular expression as the first parameter.
  • #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] [Broken]
[/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] [Broken]
Redirect 301 /oes.htm [PLAIN]https://example.com/file.html[/PLAIN] [Broken]
[/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] [Broken] [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] [Broken]
The first parameter is a regex, of course, with the slash escaped and "$" signifying end-of-string.
 
Last edited by a moderator:

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
22
Views
5K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
15
Views
7K
  • Programming and Computer Science
Replies
4
Views
3K
Replies
1
Views
832
Replies
152
Views
4K
  • Computing and Technology
Replies
10
Views
3K
  • Programming and Computer Science
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Programming and Computer Science
Replies
5
Views
6K
Back
Top