301 redirect folder url to root url using htaccess

Our SEO department recently tweaked the URLs of a client website in order to improve the search engine rankings. The change was minor and they just removed a category path from the URL which shortened the actual length of the URL. There was one problem. The website was already indexed in Google and even though the change was minimal the effect was on hundreds of URLs. When any one clicked on the old URL indexed in Google the 404 page showed up which was a Big NO NO if you are some one managing a website having more than 50,000 GBP of sales.

The solution was an addition of one line in the .htaccess file which would automatically redirect the visitor from the old URL to the new URL.

I added the following line which resolved the problem.

RedirectMatch webman/(.*)$ http://www.adeelsarfaraz.com/$1 [R=301,L]

Please note that the above is an example. You can replace the webman to your path name and the domain name to the relevant domain name.


How to disallow executable scripts from executing using htaccess

I came across an issue recently in which the client complained that his hosting provider had suspended his website account due to large number of spam emails being sent from this website. The client website was a small 5 page website and CAPTCHA had been implemented on the Contact Us form.

After talking with client’s hosting support I found that the emails were being sent from .php and .pl scripts in the images folder. The images folder had 777 permission meaning that any file could be read, written to and modifiied. I first changed the permissions to 755 and then removed all executable scripts from that folder.

Next I uploaded an .htaccess file to disallow any executable script from running in the images folder. The contents of the .htaccess file are as follows

 Order Allow,Deny
 Deny from all

As can be seen from above the htaccess will now disallow an script or file which does not belong in the images folder. Please see below

Hope the above helped and let me know if you encounter any problems.

Why am I not able to view any images on my PHP website on FastCGI?

Most probably you have .htaccess files in your subfolders which are there to restrict access to files and other resources in those subfolders. FastCGI based web servers sometimes do not serve pages properly in cases where the .htaccess files do not have Options entry in the AllowOverride apache directory configuration. A far simple resolution would be to disable the .htaccess but it’s not recommended at all.

If you are encountering this issue and would like the help of freelance web developer then I would be very happy to help you.

.htaccess file not showing up in FTP client

Our SEO team was working on a website and they had made some changes to the .htaccess file and uploaded it onto that website. The problem was that they did not know that the website already had its own .htaccess file. Hold on! Why did they not know?

That’s because the FTP client did not show the file. This does seem surprising but it’s true. FTP clients do not generally show the .htaccess file and you have to manually make some settings to the FTP client so it shows up.

So, after the file was overwritten the website URLs stopped working and we had to download the SEO module afresh and make the relevant changes and re-upload it.

The moral of the story: Don’t believe your eyes. Use a bit of your head. If the website has SEO friendly URLs enabled and its hosted Linux then there MUST be an .htaccess file there.