Modify .htaccess
-
Hi everybody,
I need to modify the .htaccess in order to include a 301 redirect.
But I am having some problems with this.
I downloaded the file into my computer and then modified it with windows notepad, but when I upload it again to the server it is not working and turns down my website.
Even if I do not change anything on it. So I guess there is a problem in the saving process.
Any Idea or suggestion?
Thanks,
G.
-
I highly recommend Notepad++ for that reason. Better control over the line return problems. Windows Notepad leaves much to be desired in this area.
-
no worries, also for the future FTP programs can alter the encoding also.
-
Assuming it's not actually an issue with the code in the .htaccess file, it's probably something like Alan says, an encoding issue. It might also be the FTP upload method you're using to the server as well borking something in the file (i.e. FTP transfer type setting in your FTP client - try forcing the setting to "ASCII" rather than automatic or binary), or possibly a permissions issue on the file when it's uploaded, though that seems unlikely.
If you can edit in place on the server (using ssh and an editor like vim) then that would rule out those kind of problems.
-
It was that!
Thank you!
-
Perfect Alan! it worked.
Thank you very much!!
-
Yes, it's safe - don't see a reason why that can be an issue.
Also take Alan's advice - maybe you are saving it a different format and that can also be an issue.
-
Is it safe to post all the content over here?
-
i work with windows server not linux, but i would say it is the encoding, try saving it wirth different ecoding
Try saving as UTF-8 or ASCII, you can do this on the save as dialog box
-
Can you post the content of the htaccess here so we can have a look ?
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Htaccess maximum size?
Hello all, The company that develops our website recently contacted and asked me if we could remove a large amount of URL rewrites. I've described a few factors and my main questions below. Some information: One year ago we did a large migration. We went from 27 websites to one main website. We have got about 2000 rewrites in the htaccess file. And the file is 208kb. A lot of links from our old domains still have incoming traffic which are handled by the rewrite rules mentioned above. Questions:
Intermediate & Advanced SEO | | DPA
The company that develops our website said that the htaccess file is too large and is causing or could be causing us website performance issues. They have asked us to remove URL rewrites.
My question is:
a) How many rewrites is too much?
b) Is the filesize of the htaccess of any importance or is it just the amount of rewrites in the file?
c) Could we solve any potential server/website performance issues due to a large htaccess file in any other way? Increasing some values like 'post_max_size' or by any other solutions handled serverside? I do not have a lot of knowledge of htaccess rules but I've seen websites that handled over a million of rewrite rules. This is why I'm having doubts on whether removing URL rewrites is the only solution and possibly not the best solution for us. Hopefully you can help me any further and with the best way to proceed without losing traffic or causing 404 pages. Thanks in advance!
Iordache Voicu0 -
6 .htaccess Rewrites: Remove index.html, Remove .html, Force non-www, Force Trailing Slash
i've to give some information about my website Environment 1. i have static webpage in the root. 2. Wordpress installed in sub-dictionary www.domain.com/blog/ 3. I have two .htaccess , one in the root and one in the wordpress
Intermediate & Advanced SEO | | NeatIT
folder. i want to www to non on all URLs Remove index.html from url Remove all .html extension / Re-direct 301 to url
without .html extension Add trailing slash to the static webpages / Re-direct 301 from non-trailing slash Force trailing slash to the Wordpress Webpages / Re-direct 301 from non-trailing slash Some examples domain.tld/index.html >> domain.tld/ domain.tld/file.html >> domain.tld/file/ domain.tld/file.html/ >> domain.tld/file/ domain.tld/wordpress/post-name >> domain.tld/wordpress/post-name/ My code in ROOT htaccess is <ifmodule mod_rewrite.c="">Options +FollowSymLinks -MultiViews RewriteEngine On
RewriteBase / #removing trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301,L] #www to non
RewriteCond %{HTTP_HOST} ^www.(([a-z0-9_]+.)?domain.com)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L] #html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [NC,L] #index redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/
RewriteRule ^index.html$ http://domain.com/ [R=301,L]
RewriteCond %{THE_REQUEST} .html
RewriteRule ^(.*).html$ /$1 [R=301,L]</ifmodule> The above code do 1. redirect www to non-www
2. Remove trailing slash at the end (if exists)
3. Remove index.html
4. Remove all .html
5. Redirect 301 to filename but doesn't add trailing slash at the end0 -
Htaccess Issue: URL not resolving properly
I am merging a niche site, tshirts.com to another site mainsite.com. I am using an htaccess file on a linux server, and the homepage of the niche site is being directed to the corresponding category page on the main site (i.e nichesite.com to mainsite.com/niche.html). Everything else is also a page to page redirect. I have something like this in the htaccess file: Redirect 301 http://tshirts.com/ http://www.mainsite.com/tshirts.html
Intermediate & Advanced SEO | | inhouseseo
Redirect 301 http://tshirts.com/blue.html http://www.lampclick.com/blue-t-shirts.html
Redirect 301 http://tshirts.com/white.html http://www.mainsite.com/white-t-shirts.html
Redirect 301 http://tshirts.com/black-tshirts.html http://www.mainsite.com/bk-t-shirts.html When I check 301 for lets say http://tshirts.com/blue.html, I get: http://tshirts.com/blue.html -** 301 Moved Permanently** http://www.mainsite.com/tshirts.htmlblue.html -** 302 Found** http:www.mainsite.com/ How do I fix this? Why is everything being appended to minsite/tshirts.html? I appreciate your help.0 -
.htaccess 301 Redirect Help! Specific Redirects and Blanket Rule
Hi there, I have the following domains: OLD DOMAIN: domain1.co.uk NEW DOMAIN: domain2.co.uk I need to create a .htaccess file that 301 redirects specific, individual pages on domain1.co.uk to domain2.co.uk I've searched for hours to try and find a solution, but I can't find anything that will do what I need. The pages on domain1.co.uk are all kinds of filenames and extensions, but they will be redirected to a Wordpress website that has a clean folder structure. Some example URL's to be redirected from the old website: http://www.domain1.co.uk/charitypage.php?charity=357 http://www.domain1.co.uk/adopt.php http://www.domain1.co.uk/register/?type=2 These will need to be redirected to the following URL types on the new domain: http://www.domain2.co.uk/charities/ http://www.domain2.co.uk/adopt/ http://www.domain2.co.uk/register/ I would also like a blanket/catch-all redirect from anything else on www.domain1.co.uk to the homepage of www.domain2.co.uk if there isn't a specific individual redirect in place. I'm literally tearing my hair out with this, so any help would be greatly appreciated! Thanks
Intermediate & Advanced SEO | | Townpages0 -
Quick htaccess question
Hi! I'm trying to do a 301 from www.stevesims.com/index.htm to www.stevesims.com. I know I need to use the request command to avoid an infinite loop, but I can't quite figure out the correct code. Here's the first part of the htaccess file. RewriteEngine On RewriteCond %{HTTP_HOST} ^stevesims.com
Intermediate & Advanced SEO | | Blink-SEO
RewriteRule (.*) http://www.stevesims.com/$1 [R=301,L] RewriteCond %{HTTP_REFERER} !^http://stevesims.com/.$ [NC]
RewriteCond %{HTTP_REFERER} !^http://stevesims.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.stevesims.com/.$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.stevesims.com$ [NC]
RewriteRule .*.(jpg|jpeg|gif|png|bmp)$ - [F,NC] Any suggestions would be much appreciated.0 -
Htaccess 301 regex question
I need some help with a regex for htaccess. I want to 301 redirect this: http://olddomain.com/oldsubdir/fruit.aspx to this: https://www.newdomain.com/newsubdir/FRUIT changes: different protocol (http -> https) add 'www.' different domain (olddomain and newdomain are constants) different subdirectory (oldsubdir and newsubdir are constants) 'fruit' is a variable (which will contain only letters [a-zA-Z]) is it possible to make 'fruit' UPPER case on the redirect (so 'fruit' -> 'FRUIT') remove '.aspx' I think it's something like this (placed in the .htaccess file in the root directory of olddomain): RedirectMatch 301 /oldsubdir/(.*).aspx https://www.newdomain.com/newsubdir/$1 Thanks.
Intermediate & Advanced SEO | | scanlin0 -
301 Redirect htaccess
Hi Guys, I have a website that has plenty of links with parameters. For example:
Intermediate & Advanced SEO | | UrbanMark
http://www.domainname.co.uk/index.php?app=ecom&ns=catshow&ref=Brandname-Golf-Shorts&sid=201v04gxs2hlozv161tfo43qk98583el I want to place a wildcard redirect on the .htaccess but don't know what exactly code for this. Ideally I want the URLs above to be: http://www.domainname.co.uk/Category/Brandname-Golf-Shorts Any help pls. Thanks,
Brucz0 -
.htaccess files
I am working with a clients website which has multiple htaccess files (.htaccess , .htaccess.holiding, and .htaccess.live -all in the same directory) My question is how does a server process these files? All 3 files? Currently the domain has 301 redirect showing for the home page to the mobile site (which is a problem) in one of the files (.htaccess but not others) Has anyone come across this before with regard to SEO problems?
Intermediate & Advanced SEO | | OnlineAssetPartners0