Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

301 Rdirect - about.html to about/

Featured Replies

Probably asked before but in htaccess, how do I go about implementing a 301 redirect from example: about.html (or about.php) to about/ (no file extension).

 

Thank you.

  • Author

Here is a link I found - https://www.rapidtables.com/web/tools/redirect-generator.html. Thoughts on it's accuracy?

​For a permanent 301 redirect solution on a Linux platform with GoDaddy, which is a better solution in your opinion?

​htaccess:

 

# Permanent URL redirect - generated by www.rapidtables.com
Redirect 301 /about.html http://www.myurl.com/about/

 

or php:

 

<?php
// PHP permanent URL redirect - generated by www.rapidtables.com
header("Location: http://www.myurl.com/about/", true, 301);
exit();
?>

​This is for a simple redirect from about.html to about/ without a change in domain name or host.

 

The following would be added to the htaccess file to hide the page extensions:

PHP EXTENTION REMOVAL

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)$ $1.php [NC,L]

HTML EXTENTION REMOVAL

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)$ $1.html [NC,L]

 

​I assume this is correct?

Careful mate, bulk doing anything when discussing 1 page is like cracking a walnut with a sledge hammer. If the page is true .html then obviously the php won't work in this instance. Neither of those htaccess examples are 'cut and shut' if you don't understand them, seriously take a few moments to understand rather than looking for a copy and paste solution, they are rewrites and not 301 redirects, big difference. I'll break it down;

RewriteEngine On

This lets you rewrite urls using a RewriteRule. But missing IMO;

RewriteEngine On
RewriteBase /

Rewrite base here tells the server to use root down, meaning you can shorthand the redirect url without the full www. etc.

RewriteEngine On
RewriteBase /
RewriteRule ^/about/ /about.html

Ok rewrite rule; if the url is /about/ then load /about.html.

RewriteEngine On
RewriteBase /
RewriteRule ^/about/ /about.html
Redirect 301 /about.html /about/

This 'should' now redirect people hitting /about.html to /about/. That said this is untested in your environment, not 100% you won't get a 301 loop. Future reference to keep things simple make all .html pages end in .php even if they don't 'technically' use php as it opens up the opportunity to use php in the file if required at a later date.

  • Author

Ok. So I can use the below to 301 redirect about.html to about/ (after of course addl code is used to hide the extension in the first place?

 

Hide extension:

 

UrlRewrite (do so for each page in the directory?):

 

RewriteEngine On

RewriteBase /

RewriteRule ^/about/ /about.html

Redirect 301 /about.html /about/

 

And this should work on Linux servers? I appreciate your help.

 

 

Also, if I am using redirects from nonwww to www as well as index.html to main url, is there a particular order all of this needs to be in? I'll have to add in redirect from http to https another time...

Edited by RobertS

Extension removal is different than rewrites in a fashion. The example you give will drop .html off every .html file in favour of /filename/. This sort of bulldozer approach can come unstuck very quickly; for example I've got a folder called /images/, i make a page called /images.html, what will happen?

 

Mate pm me a real world example so I can see the current structure vs desired structure, i'd be able to help more if I knew more but you might not want to post your structure to the world ;)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.