1

I have never worked with .htaccess before and was going through the documentation of Redirect Directive here : http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect .I wanted a 301 redirect from http://localhost/testing/about.html to http://localhost/testing/about-me.html . I created a .htaccess file in http://localhost/testing/ like below :

<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /about.html http://localhost/testing/about-me.html

</IfModule>

The redirect is not working . I am sure I am doing something wrong . Could somebody please tell me why the redirect is not working ?

Knownow
  • 353
  • 1
  • 4
  • 17
  • Does this answer your question? [.htaccess URL redirect](https://stackoverflow.com/questions/3374696/htaccess-url-redirect) – Example person Jan 13 '20 at 08:22
  • mod_rewrite version seems to be working but the mod_alias version is not . The URL remains unchanged to http://localhost/testing/about.html allthough the content of http://localhost/testing/about-me.html is getting loaded . I want the URL to be http://localhost/testing/about-me.html . I checked http.conf and LoadModule alias_module modules/mod_alias.so was uncommented . – Knownow Jan 13 '20 at 12:02
  • I just checked mod_alias is enable but Redirect is not working – Knownow Jan 13 '20 at 12:08
  • Try my answer please. And also, try restarting apache once. And try it with the double quotes. – Example person Jan 13 '20 at 12:19
  • Use the mod_rewrite version, is there any problem with using the rewrite version? – Example person Jan 13 '20 at 12:22
  • Check your error.log file – Example person Jan 13 '20 at 12:24
  • I restarted apache , tried with quotes and no quotes . There are no errors in the log . The problem with rewrite is the URL in the browser doesnt change . I need it to change and fetch the changed URL . – Knownow Jan 13 '20 at 12:34
  • Try a different browser. If this also doesn't work, I suggest you to go with the rewrite rules – Example person Jan 13 '20 at 12:35
  • permanent doesnt work , using xampp on windows 7 – Knownow Jan 13 '20 at 12:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/205866/discussion-between-chi-c-j-rajeeva-lochana-and-knownow). – Example person Jan 13 '20 at 12:44
  • You have to use mod_rewrite to redirect specific files. The "redirect" function from mod_alias only considers the path part of the URL, so in your case "/about.html" is really being considered as "/" with "about.html" appended to the destination. Stupid design in Apache. – Adambean Apr 30 '21 at 11:06

1 Answers1

1

Make sure mod_alias is loaded. There is the other way of making the same redirect, but with mod_rewrite:

<IfModule mod_rewrite.c>
RewriteEngine On #Use RewriteEngine only once
RewriteRule ^about.html http://localhost/testing/about-me.html
</IfModule>

Or: (With mod_alias loaded)

<IfModule mod_alias.c>
Redirect 301 "/about.html" "http://localhost/testing/about-me.html"
</IfModule>
Example person
  • 3,198
  • 3
  • 18
  • 45