Hot answers tagged

9

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


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

Use this. It should save you from two headaches. RewriteEngine On RewriteCond %{HTTP_PORT} 80 [OR] RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] this also allows any URL that starts with http://www.example.com/ or that connects to port 80 (the standard web port) to redirect to https://example.com/


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

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


4

I’m not sure what the problem is in your case (I tested your snippet and it works as expected), but maybe this works for you: RewriteEngine On RewriteRule ^foo$ /redirect.html [redirect=temp,last] I’m not an .htaccess expert, but I guess this would even be faster, because the RewriteRule pattern gets processed before RewriteCond.


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

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


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


3

I have just discovered the solution! This seems to be a GoDaddy special. Domains in GoDaddy are kept in subfolders; e.g. mydomain.com might be held in a subfolder called md. Curiously, the start of %{REQUEST_URI} includes this string. Therefore, my RewriteCond should have read: RewriteCond %{REQUEST_URI} ^/md/foo$ It is not needed if the string does ...


3

Hey guys I finally figured it out, some how the code that works to do this in Modx CMS is below! This code shows you how to install it in a folder on your server. It tells the htaccess file to read the .html extension and loads up the page without a problem. #works, so happy!! # MODX supports Friendly URLs via this .htaccess file. You must serve web # ...


3

That should be: RewriteEngine on RewriteCond %{HTTP_HOST} !^www.domain.org$ [NC] RewriteRule ^(.*)$ http://www.domain.org/$1 [L,R=301] The "$1" tells mod_rewrite to add the matched text from inside the parentheses in the pattern to the rewritten URL, which is what you want.


3

You need to know the relationship between the project-folder and the sub-folder, ie. which sub-folder a particular project is in. If there is no pattern between project-folder and sub-folder and being restricted to .htaccess then I think you'll need to specify each rewrite manually. You can internally rewrite all requests for the respective project to ...


3

While it isn't impossible to host multiple secure sites on a single IP address, thanks to SNI and SAN, the redirect you're trying to do is impossible without one of the aforementioned solutions. In order to receive a redirect from https://www.olddomain.com, the browser must have already requested that URL using SSL/TLS, and is expecting an encrypted response ...


3

You can just add another RewriteCond directive: RewriteCond %{REQUEST_URI} !^/activity RewriteCond %{REQUEST_URI} !^/members RewriteRule ^(.*)/([0-9]+)/$ /$1/S$2/ [R=301,L] Multiple RewriteCond directives are AND'd together by default. The OR flag can be used if required. I've removed the NC flag - unless you specifically need a case-insensitive match. As ...


3

You can do this by adding another condition. RewriteCond %{REQUEST_URI} !^/members [NC] RewriteCond %{REQUEST_URI} !^/activity [NC] RewriteRule ^(.*)/([0-9]+)/$ /$1/S$2/ [R=301,L] Or, sometimes simpeler, use the OR of a regex: RewriteCond %{REQUEST_URI} !^/(members|activity) [NC] RewriteRule ^(.*)/([0-9]+)/$ /$1/S$2/ [R=301,L] I've removed the .*$ ...


3

To redirect everyone else, apart from your IP address (eg. 123.123.123.123), to the /blog subdirectory then you can use something like the following in .htaccess: RewriteEngine On RewriteCond %{REQUEST_URI} !^/blog/ RewriteCond %{REMOTE_ADDR} !=123.123.123.123 RewriteRule (.*) /blog/$1 [R=301,L] If the requested URI does not start with /blog/ and the IP ...


3

The space is a delimiter (ie. a special character) in .htaccess so must be backslash escaped if you want to match a literal space in the regex. Eg. DV\ CRAWLER. (Otherwise you are likely to get a less than helpful 500 Internal Server error.) Or, you can use the shorthand character class \s which matches any white space character (space, tab or new line / ...


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