We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

.htaccess How do I add 301 redirects?

Development and Programming

conv's avatar
conv
26 posts
16 years ago
conv's avatar conv

Here is the code that removes index.php from the url.

RewriteEngine On

RewriteBase /

# remove the www
RewriteCond %{HTTP_HOST} ^(www\.$) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

# Remove index.php
# Uses the "include method"
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 ^({ee:template_groups}|{ee:pages}members|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

I have added redirects to the bottom of this file ie Redirect 301 http://www.mydomain/newsroom/newsroom.asp http://www.mydomain/newsroom

The old site was hosted on a asp platform and the redesigned site is now hosted on php / expression engine. I have created loads of redirects links as above for the new site. These redirects are not working is there a special way in which I should enter them? I am using LG .htaccess Generator 1.0.0

Any help appreciated.

Thank you

       
Nevin Lyne's avatar
Nevin Lyne
370 posts
16 years ago
Nevin Lyne's avatar Nevin Lyne

Everything in a .htaccess file is processed from the top down for every request to the server. The URLs you are trying to redirect are likely being rewritten prior to your Redirect lines. Try placing it above the Rewrite On line (as Redirect does not need the Rewrite engine to be on at that point, you will probably want to modify the Redirect line to be a URI to a full URL:

Redirect 301 /newsroom/newsroom.asp http://www.mydomain/newsroom/

RewriteEngine On

       
conv's avatar
conv
26 posts
about 16 years ago
conv's avatar conv

Thank you very much! Problem solved, it did not help that I had Redirect 301 http://www.mydomain/newsroom/newsroom.asp http://www.mydomain/newsroom

instead of

Redirect 301 /newsroom/newsroom.asp http://www.mydomain/newsroom

Redirects now working … thanks again 😊

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.