Tag Info

Hot answers tagged

18

Either way is fine from a user perspective, as long as both work when you type them in the address bar. The problem is having both without redirecting one to the other. Google and other search engines will count www.example.com and example.com as two different URLS. This, along with inconsistently ordered URL parameters, is one of the major causes of ...


14

Strong vote for a dedicated 404 page. Less confusing for the user Allows you to see more easily if something is wrong (through web server error log, your own logging script and/or Google Analytics) You can tailor the page towards the situation (for example display a list of product categories) Allows search engines to clean up their indexes. No longer ...


13

Wget is just a command line tool for linux that fetches resources over HTTP - all this tells you is that someone accessed your site via a command line, it could have been a bot scraping you, but there's no way of knowing for sure If your site is password protected properly, there shouldn't be any need to block particular user agents :) x


10

You could actually remove .html from the files on your server and set settings in htaccess so that they get served up as html files, but that's probably not what you're looking for. Do this : RewriteEngine on # Check this condition to ensure that it's not a directory. RewriteCond %{REQUEST_FILENAME} !-d # Check this condition to ensure that there's a file ...


10

HTTP clients cannot tell what caused a server to return a 30x redirect status, so it makes absolutely no difference.


10

I've been told that .htaccess should be avoided when possible, as it reduces the server performance and new servers disables it or just don't implement it anymore. The part about compatibility is absolutely not true; the part about performance is kinda true but probably irrelevant for you. What the person you quote was probably talking about is that ...


10

Try this RewriteEngine On RewriteBase / RewriteRule ^edit/id/([0-9]+)/?$ edit.php?id=$1 [NC,QSA,L]


10

You can't stop a site linking to you with technical measures, but you can identify requests which have come from that site/url and block these in .htaccess - RewriteEngine on RewriteCond%{HTTP_REFERER} ^http://www\.site\.com [NC] RewriteRule index.html http://www.go-away.com/goaway.html [R] The above rules will probably need some tweeking, but the idea ...


9

You are looking for the Query String Append flag - e.g. RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^search/(.*)$ search.php?q=$1 [QSA] See the mod_rewrite documentation for a full description of RewriteRule flags.


8

Just specify a page that all 403 error messages should be shown: order Deny,Allow Deny from all Allow from my.ip.add.ress ErrorDocument 403 /forbidden.html You can customize this page to look any way you wish.


8

How about a little corbomite maneuver? RewriteEngine on RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?turkyoutube.org.*$ [NC] RewriteRule ^(.*)$ http://127.0.0.1/$1 [R=401,L] Note, untested but should redirect requests from them back to themselves with a 401 Not Authorized status code. That is, if the bot even handles redirects (very unlikely), but it ...


8

Options: Set up a local site for testing purposes. Something like WAMP should do the trick. If you're going to do the testing on your live server, temporarily block your site while doing your testing. A 307 HTTP response would be appropriate. Use basic authentication to keep crawlers and everybody else out while you do your testing. Since your site will be ...


7

This snippet will force the www to always be in thew URL. I don't know if that helps you or not: Options +FollowSymlinks RewriteCond %{HTTP_HOST} !^(www\.|$) [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


7

Your pattern ([^/]+)/?$ will match fred as well as index.php. The key here -- the way how [L] flag works. After initial rewrite of fred occurs it goes to next rewrite iteration, where it will rewrite index.php?a=fred to index.php?a=index.php. Because URL was rewritten, it goes to 3rd iteration, where index.php?a=index.php will be rewritten to the same URL ...


7

You're looking for a Geoloction (Geoblocking) database which would give you access to the typical IP ranges for the countries you need to block. This is not absolute or completely trustworthy information though. Country level geoblocking is mostly effective but anything like city/state/zip code level information should be treated with great caution. I've ...


7

Technically speaking http://www.new.com/tag/relationships and http://www.new.com/tag/relationships/ are two different pages just like http://www.example.com/ and http://www.example.com/index.html are two different pages even though they pull up the same page. To make sure the search engines understand that http://www.new.com/tag/relationships and ...


7

Store your old and new redirect paths in a database. Redirect 404 errors to a special 404 page. With Apache and PHP, you could do this with the ErrorDocument directive in your .htaccess: ErrorDocument 404 /404.php In the 404.php script, get the referring page with $_SERVER['REQUEST_URI'], look up the old URL path in your database, and serve a 301 redirect ...


7

You need to drop the 'http:' prefix from all image (and any other) links on your site. When you do so, your browser will default to whatever protocol the page loads with. For example this is best: <a href="//www.example.com/"> And this is not: <a href="http://www.example.com/"> The top example is perfectly valid markup and you will load all ...


7

Empty Virtual Host With virtual hosting, all traffic is routed to an IP address and then Apache matches the hostname. When virtual hosting using NameVirtualHost is enabled, the site that responds to the IP address is the first one listed in the Apache configuration file. So you can use a null virtualhost: <VirtualHost 192.168.1.1:80> ...


6

Here are the disadvantages of basic authentication according to WikiPedia: Although the scheme is easily implemented, it relies on the assumption that the connection between the client and server computers is secure and can be trusted. Specifically, if SSL/TLS is not used, then the credentials are passed as plaintext and could be ...


6

So .. you have more than 1 .htaccess file: one in the root folder and one in /dev folder. Where did you put rules from @Alex -- root or /dev .htaccess? Most likely in root. That is the reason why it did not worked. Thing is -- if Apache sees rewrite rules in lower level folder, it will NOT execute them from parent folder UNLESS your lower level .htaccess ...


6

See Working with multi-regional websites by Google. It covers this in detail.


6

To implement such redirect using mod_rewrite and .htaccess you need to use RewriteMap directive which cannot be placed in .htaccess -- only in server config / VirtualHost context. If you have such access: 1. Place this line inside <VirtualHost> block for your site: RewriteMap lc int:tolower 2. Place this in your .htaccess: RewriteCond ...


6

It means "this matches the start of the string". So in your example the rule does the rewrite if there's the start of the string (^) any character (.) any number of characters (*) the end of the string ($) In other words, this whole expression matches any string.


6

The best way is to use 301 redirects in your .htaccess file, the 301 code signals to google that the url has been permanently redirected. I'd also recommend signing up for Google Webmaster Tools and submitting a sitemap to them, if you haven't already, as this will help them to understand the changes you're making to your site. redirect 301 /old-url ...


6

I guess technically it would slow it down a bit, as in order to follow the rules the server would have to first process them. However I don't think it would slow the server to a crawl, and probably wouldn't be very noticeable at all. I would hazard a guess and say it is caused by the shared hosting at GoDaddy. I previously had hosting with them and found ...


6

Can the .htaccess file slow down a website to a crawl? If so, are there better ways to solve these problems with different rewrite rules and such? AllowOverride all impacts server performance as Apache must check for .htaccess files and parse directives with each request - if possible, keep all directives in the VirtualHost configuration for your ...


6

I would have said that placing these sensitive files above the document root would be preferable. And perhaps easier to manage if they are all contained in a particular directory, however... Using .htaccess to prevent access to all .db and .exe files and return a 403 - Forbidden. <Files ~ "\.(db|exe)$"> Deny from all </Files> Unless you have ...



Only top voted, non community-wiki answers of a minimum length are eligible