Hot answers tagged

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


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


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


5

I know this is an old question, but it shows up early on google so I thought I would answer it. You can now enable gzip on GoDaddy by adding the following to the .htaccess in your root directory. AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript Source - GoDaddy Support


5

A valid https connection is required for HTTPS to HTTP to work for a particular domain. Currently, since http://yourtechchick.com is not available via https:// with its own SSL certificate, make sure that any .htaccess redirect you are applying is for https://your-techchick.rhcloud.com. Why has google indexed [an] https version of my website? I do ...


5

Yes, the same way any request can be "dynamic". However, you would not redirect (as in your example code), you should internally rewrite using mod_rewrite. (The same as what Drupal is probably already doing.) For example, in your root .htaccess file: RewriteEngine On RewriteRule ^robots\.txt$ robots.php [L] RewriteEngine should only occur once (although ...


5

You can't do a simple redirect of "all articles" if the source and destination IDs in the URL are different and there is no easy way to map between the two. For example, how do we know that 966aaafd8 maps to 8a4521384? In order to do this you would need to create a RewriteMap in your server config (containing all the source / destination IDs) or rewrite ...


5

What seems to be happening, is your rule is being matched and then apache is sending a 301 redirect response telling the browser to generate a new request for /web-browser-benchmarks-firefox-chrome/ Chrome is generating this request - as instructed, but when your webserver see's this new request - your rule is matching that request too - again telling ...


5

Removing the dot or period from htaccess files and thus making it unhidden - A dangerous move? You definitely have to be careful how you do it, as you might otherwise compromise the security of your server. There are basically two dangers that you could encounter: Reading your htaccess File htaccess files are nothing special, and if you just rename ...


4

In your root .htaccess, using mod_alias: Redirect 301 /home / However, if you are already using mod_rewrite (very likely that you are if this is still a Joomla site) then you should use mod_rewrite: RewriteEngine On RewriteRule ^home/(.*) /$1 [R=301,L] Nothing else to do in Google Search Console (formerly known as "Google Webmaster Tools").


4

I don't think you can make it completely generic, since you'll need to make exceptions for your subdomains, unless there is a pattern to your subdomains? A workaround is to add each subdomains to the regular expression. Well, yes unfortunately... RewriteEngine on RewriteCond %{HTTP_HOST} !^(wiki|sub2|sub3)\. RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) ...


4

Not being able to find your JavaScript and CSS files is a client-side/browser issue related to your URL-path, it's not something that should be fixed in .htaccess (at least not in this case) - although it is because you are changing this URL-path (in .htaccess) that you are experiencing this problem. As closetnoc suggests in comments this problem is caused ...


4

Just because a URL is in Google's index doesn't mean that it was submitted through webmaster tools or search console. Google includes most URLs in the index only because it finds links to them on other sites. Most of the time Google won't index a redirecting URL (including a shortened URL.) Usually Google prefers the destination. If the redirect URL ...


4

SOLVED! Thanks to you guys. Solution: # Turn Rewrite Engine On RewriteEngine on # Set the base to /games/ so we need not include it in the rules RewriteBase /games/ #Rewrite for achilles.php?games_path=xxxxxxxxxx.yyy&category_id=zzz RewriteRule ^([0-9a-zA-Z_-]+)/([0-9]+) $1.php?games_path=$1.swf&category_id=$2 [NC,L] ...


4

# Use PHP5.4 as default # Changed PHP handler from application/x-httpd-php54 to application/x-httpd-phpbeta on Thu Dec 17 16:50:26 MST 2015. AddHandler application/x-httpd-phpbeta .php # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Insert redirect based rewrites here. # Example: RewriteRule ^redirectme$ ...


4

Remove "http:" from the script src url, like: <script src="//code.jquery.com/jquery-2.1.4.min.js"> In case the problem insists, check if shows errors through Chrome Dev Console and paste it here.


4

Removing the dot is renaming the file. Once you do that, the web server won't be able to find the file, so its contents will no-longer effect web server behavior. If after considering all the disadvantages of running a non-standard set-up you you still want to rename, it you can configure apache to look for the file under a different name, but it may make ...


4

As @Mike has already stated in comments, /public should be your DOCUMENT_ROOT and /includes should be entirely outside of your publicly viewable files, otherwise you are not really practising what you have been taught, to "separate publicly viewed webpages from included files and other, more sensitive information." Your files that you request via AJAX ...


4

Absolutely. Your .htaccess file is located in the root directory of the website and can be accessed via FTP.


4

how this workaround indeed works PHP runs later in the request, so most of the time you can simply override any headers that Apache has already set in your PHP code. That's pretty much it. (Aside: Sending 403s through your 404 handler in this way obviously makes it harder to trigger a real 403 from your Apache config/.htaccess, if you should need to.) ...


4

Server version: Apache/2.4.12 (Win32) Is it possible to make website a variable? Not before Apache 2.4.13 unfortunately. Can .htaccess auto detect the SubFolder (including SubFolder depth)? This depends on the module you are using in .htaccess, rather than .htaccess itself. For instance, mod_rewrite (when used in a per-directory context) ...


3

This assumes that p, id or catid always appears at the start of the query string, and that the value of this parameter is the "file" basename in the new URL, as per your code examples. RewriteEngine On RewriteCond %{QUERY_STRING} ^(p|id|catid)=(\d+) RewriteRule ^$ /%2.php? [R=301,L] The ^$ pattern only processes requests for the document root (ie. ...


3

RewriteRule ^login$ /login.php? [L,R=301] You need to remove the ? on the end of the RewriteRule substitution. This is effectively creating an empty query string, removing anything that is passed in the request. RewriteRule ^login$ /login.php [L,R=301]


3

In order to match "undefined" at the end of the URL-path you need the regex pattern undefined$. The pattern ^undefined$ (which you've used in your question) matches the exact URL "undefined", which is never going to match, unless the request is for http://example.com/undefined. This directive should go at the top of your .htaccess file (after the ...


3

If you're getting alot of requests with undefined added to the URLs and you know the things accessing those URLs are people and not robots, you're much better off using HTTP status code 301 and redirecting the URL to the correct one. Using status code 204 will not help because it means "No content" and the user will then need to manually modify the URL in ...


3

There's actually a few ways, take your pick... You could use the method which involves doing nothing... Most browsers nowadays can establish content-types without having an file extension, they will download the first few bytes and discover the type then process it within a blink of the eye. However, its not a perfect method. Using JavaScript to remove ...


3

tl;dr You need the L flag on your redirects, ie. [R=302,L]. RewriteRule ^(.*)$ http://meow.co.uk/$1 [R=302] Bit of an aside, but... the RewriteRule pattern should be ^bar/meow/(.*) (as mentioned in my answer on your other question), otherwise you won't get the working redirects that you've stated. For external redirects you generally want to use the L ...


3

RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 [R=301,L] Yes, that line removes a trailing slash from the URL. However, you would need a condition before that to prevent a rewrite loop if mod_dir (DirectorySlash) is active and you are requesting a filesystem directory. And that's probably the problem here. If you request /directory, where "directory" is an ...


3

Well this is already done as best it can by default. When you try to access fonts from another domain your browser will block this s a cross origin request (unless you explicitly add a "Access-Control-Allow-Origin" header in your htaccess file). Try it from a development server and you'll see what I mean as you'll get errors in the Console log of the ...


3

I'm partly confused by your question, so I'll answer it the best I can. To set permissions on any file on a server (including php files) there's a couple of ways. If you have a web file manager interface, you can access that and set php file permissions through that. If you have direct FTP access to the server, you can use your FTP program to set php file ...



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