Tag Info

Hot answers tagged

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


5

No this is not good. Google did not intend for nofollow to be used for internal links. It is meant to be used for links that you do not have editorial control over. This is going to hurt you a lot. Your .htaccess code is not adding nofollow to your links. It is not possible for .htaccess to alter your HTML like that. Something else is causing your problem. ...


4

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.


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

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/


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


3

I was serving my static files using Django while my media files using Apache. Serving my static files through Apache solved this issue.


3

The goal would be to keep the redirects up as long as possible, ideally forever. Why? Users will have bookmarks with the old URLs and other websites will have links to the old domain. These may never go away and you would like to keep them working if at all possible. That's just good usability (i.e. a good user experience). You could easily accomplish this ...


3

From the mod_rewrite documentation you need to use the NE (no escape) flag when your rewrite rule has a hash: RewriteRule #(.+)$ /? [L,R=301,NE] You commented that the NE flag may only apply to the target URL and not the rewrite pattern. If that is the case, another approach would be to escape the # sign. mod_rewrite supports \x style escape sequences. ...


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

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\.)(.+) ...


2

By default the query string on the requested URL is appended to the rewritten/redirected URL. The easiest way to remove the query string from the redirected URL is to simply append a ? at the end of the RewriteRule substitution. This essentially writes a blank query string (the ? does not actually become part of the rewritten URL). So, from your example: ...


2

Your DNS example is missing a few elements. Here is how I would set things up. example.com A 10.0.11.101 www CNAME example.com sub-domain CNAME example.com www.sub-domain CNAME example.com If all are on a single web server, then the web server will take the request header and respond to the request accordingly. In this case, only your parent domain needs ...


2

Triying the same and on my search I found that symfony2 frameworks .htaccess file is doing that at least it is stated in the file that it would. I tried to use it in my own setup but didnt work. Maybe that will help you guys somehow. # Determine the RewriteBase automatically and set it as environment variable. # If you are using Apache aliases to do mass ...


2

All of the resources listed are third party ones and are externally hosted. You have no control over the caching headers sent by these URLs. You might be able to find advice specific to these scripts if you hunt around a bit, but in all likelihood you won't be able to improve your page speed score for this beyond what you're currently getting.


2

Looks like you didnt "escape" the slashes in your directive. Putting backslashes before any / . or : should make it work. Also adding the ^ and $ on the wildcard helps. Heres what we use: Standard Domain: Perhaps there is a consolidated way, but this snippet should work for a standard domain. Change the target of the first rewrite to https if you need all ...


2

For Q1, the - doesn't mean that processing or iteration would be stopped, simply that the URL path would be passed through without any filtering or processing. The file will continue to execute rules until it reaches the end of the file or a rule is met that has the [L] last rule flag appended to it. To clarify then, RewriteRule .* - ...


2

The source of your problem can be in html or in javascript, and you cannot control the links that other people put on the net too.. And because he finds a page when making a request for it, it indexes it. I miss some information to give answer with code (using a CMS? Other rules in .htaccess, etc…), but here are some ways : Write a permanent redirect in ...



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