简体   繁体   中英

Single Page 301 Redirect Not Redirecting?

I'm sure I'm overlooking something silly, but this is my first need for a redirect.

I'm trying to use the htaccess file to 301 redirect an old page to the new site's corresponding page.

HTAccess reads as follows:

<head>
</head>
Redirect 301 http://www.metalsetinc.com/about_us.html http://www.metalsetinc.com/about.html

I've got a blank line under the redirect.

Does the original page file need to remain on the server for the redirect to work? I've currently moved it to an older-version folder.

With this format, I'm simply getting a 404 error when I go to the old page.

What am I missing?

  • Your .htaccess file should have that exact name (you mentioned HTAccess )
  • It shouldn't contain any html, just instructions for Apache.

For instance, with mod-rewrite, which is very flexible and you may need later for more complex rules:

RewriteEngine On
RewriteRule ^about_us.html about.html [L,R=301]

This assumes that mod_rewrite is both installed and activated for htaccess files. If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo(); By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All

In complement to @zx81answer,

You can use Redirect instruction, from mod_alias , but as stated in doc the format is:

Redirect [status] URL-path URL

The first URL is just a path, not a full one.

So this should work better:

Redirect 302 /about_us.html http://www.metalsetinc.com/about.html

And I'm using a 302 status here. You should always start with temporary 302 redirects. When it works you can alter it to 301 permanent redirects. But using 301 redirects while testing will prevent your browser from re-trying the request. In 301 mode every response from the server is stored in the browser memory and the only way to test new rules is to close your browser first. So start with 302.

And one last suggestion for anyone who might be reading this down the road... make sure your .htaccess file is saved in a Unix format, not DOS. For me, I found it easiest to use Notepad++.

In Notepad++, go to EDIT -> EOL Conversion -> Unix/OSX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM