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 ...


15

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 ...


14

You're right that the trick is a wildcard DNS entry (indicated with asterisk) . Essentially it's a DNS entry that will match all subdomains that don't have a specific DNS entry. Then the "routing" happens on the application/website side. There is no actual DNS entry created for the subdomain, the reason that it finds a "match" when a DNS request is made, is ...


14

It's dangerous in the sense that it won't work if you do. Apache will look for .htaccess and apply those rules as it serves content. Without finding that file, Apache will proceed assuming no additional directives are necessary. .htaccess includes a leading . because it's a "hidden file" in Linux systems (which run most web servers).


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


13

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 ...


12

First Step Open file as sudo vim /etc/apache2/apache2.conf Second Step remove comment sign (#) if you find it before this line ( line number 187 approx.) AccessFileName .htaccess Third Step Then find the line where there is <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride `<b><i>None</i></b>` ...


11

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

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


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 ...


10

You can make any file dynamic. The best way to do so is not through redirects, but through rewrite rules. RewriteRule ^robots\.txt$ /robots.php [L] That way, you power it with a dynamic script, but the URL doesn't change. Most crawlers (including Googlebot) will follow redirects for robots.txt, but some crawlers will get confused if you introduce ...


9

change your htaccess file code on resource server domain (i.e. The cdn htaccess; not the source calling the resource) <IfModule mod_headers.c> Header add Access-Control-Allow-Origin "*" </IfModule> This way domain2 is allowed to access resources on the cdn.


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

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 ...


8

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 the previous character (*) the end of the string ($) In other words, this whole expression matches any string.


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 ...


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

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

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]


8

Your FTP client has a setting to show hidden files. Turn it on. Or use a client that allows . hidden files to be seen. And use SFTP as FTP sends clear-text credentials (clear-text => unencrypted as in you can retrieve them by running tcpdump or similar traffic analysis and capturing the packets).


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> ...


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

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 ...


7

Thanks for your time to look at the question, but we appeared to have figured it out: Options -Multiviews -Indexes +FollowSymLinks RewriteEngine On RewriteBase / DirectorySlash Off # remove trailing slash RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L] # rewrite /dir/file?query to /dir/file.php?query RewriteRule ^([\w\/-]+)(\?.*)?$ $1.php$2 ...


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

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 ...



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