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


12

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


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


9

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


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

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.


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

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


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

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

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


6

This is no doubt dependent on your remaining 200+ lines, but what you have posted so far would seem to be reducible to just 2 lines: RewriteRule ^patients/billing/(FAQ_billing|getintouch).html$ $1.php [L,NC] RewriteRule ^patients/findadoctor/([a-z]).html$ findadoctor.php?id=$1 [L,NC] This shouldn't be reducing your site to a crawl. As mentioned in ...


5

I think you're missing an escape for the . in your domain name: Options +FollowSymlinks Options +SymlinksIfOwnerMatch RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(.+\.)?article-stack\.com/ [NC] RewriteCond %{HTTP_REFERER} !^$ ReWriteRule .*.(png|gif|jpg)$ - [N,F,L]


5

So I wrote a set of Rewrite rules that did what you wanted, but it completely broke my website. I realized that what you want is probably not what you need. Adding trailing slashes to the end of all URLs really messes with the semantics of the URL in that you're no longer accessing the file /foo but the content listing of the directory /foo/. For example: ...


5

What I do: use vhosts for each site, including a vhost for the variant I want to suppress. This keeps all the configuration for a named site in one place. The duplication of content is minimal thanks to mod_macro. You want to issue a redirect, not rewrite internally, since the idea is to get the client to retry using the correct protocol. Make sure to only ...


5

Try converting your mod_alias redirects into mod_rewrite directives. Edit: Example below assumes that you have replaced old ASP files with PHP files under the same path. RewriteEngine on # *.asp -> *.php RewriteRule (.*)\.asp$ /$1.php [R=301,L] # tracking script RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ...


5

Try putting these rules in your .htacccess file: RewriteEngine on Options +FollowSymlinks -MultiViews # handles http redirect RewriteCond %{SERVER_PORT} =80 RewriteCond %{HTTP_HOST} ^beta\.mysite\.com$ [NC] RewriteRule ^/?(.*)$ http://www.mysite.com/$1 [R=301,L,QSA,NE] # handles https redirect RewriteCond %{SERVER_PORT} =443 RewriteCond %{HTTP_HOST} ...


5

Typically, in the root directory of your application, you'll have 3 files: index.html (<html manifest="app.manifest">...</html>). This can also be auto-generated with a server-side language such as php, jsp, Ruby ... app.manifest (CACHE MANIFEST ...) .htaccess (AddType text/cache-manifest .manifest)


5

No difference from SEO perspective. But may be an issue for some people's minds: "Pfew, stone-age html" No difference at all. This approach is also used on this site - try for yourself. The important part in URL is an ID which can uniquely identify one URL from another (take this site for example: there can be more than one question with the same title/slug ...


5

The common mistake that a lot of people do is trying to match whole URL including query string. The reality is: when matching URL, the pattern get applied to path part of it and query string has to be matched separately. In other words -- RewriteRule cannot be used to match query string directly -- only with help of RewriteCond. Considering the ...


5

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


5

Don't do testing in a production environment if at all possible. It's a recipe for disaster. Create a testing subdomain that's isolated from your production site as much as possible. This will allow you to test you changes on the server without, hopefully, endangering your production site. You can use robots.txt to block 'bots from this subdomain so it ...


5

Question: is there any recommended practice to implement this kind of homepage with permalinked URL? You should let the homepage be the homepage and you should not add redirects. Each time a robot wants to index your homepage, there would be a redirect to some new page (at least one new page each day). This is not helpful for your ranking. Instead, ...


5

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


5

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


5

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



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