40

If you are "shutting down a site" then you probably should not be "redirecting" the old site pages to a single page. An HTTP redirect sends a 301 response code, informing users and search engines the pages have moved. (Although mass redirects to a single page are likely to be seen as soft-404s by Google.) Instead, you should be serving a ...


5

It is the syntax... The <Files> directive matches against filenames only (eg. foo.php) - when the request maps to physical files on the filesystem. Since this is WordPress, I assume /test/ is not even a filesystem directory - it's simply a URL-path? You can use mod_setenvif to set an environment variable when this URL-path is requested and then set ...


4

But that redirects to example.php/ That is caused by the first (original) rule. Note that the earlier (erroneous) 301 will likely have been cached by the browser. Test with 302 (temporary) redirects to avoid potential caching issues. The Redirect directive is prefix-matching (whole path segments), and everything after the match is appended to the end of the ...


3

The nginx rewrite directive is applied unconditionally, whereas you have many conditions in your rewrite rules. Use the try_files directive instead: location = /index.php { # PHP options } location / { try_files /public$uri /public$uri/ /index.php?route=$uri; }


3

This is answered in the When (not) to use .htaccess files section of Apache HTTP Server Tutorial for .htaccess files: There are two main reasons to avoid the use of .htaccess files. The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, httpd will look in every directory for .htaccess files. Thus, ...


3

I believe you don't actually want this condition: RewriteCond %{HTTP_HOST} ^www\.example\.com$ Because that would cause an infinite redirect loop to itself, given this is from the .htaccess that applies to the https://www version, too: RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]


3

NGINX: location = /config.php { return 404; }


3

Your regular expression matches files ending with .gif, .jpg, .jpeg & .png, but you need a regular expression that matches everything but them. This is possible with a negative lookahead regular expression. From Jan Goyvaerts' regular-expressions.info: Negative lookahead is indispensable if you want to match something not followed by something else. ...


2

You can use a more dynamic approach: RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [NS] And place your robots.txt files like follows: robots/domain.tld.txt robots/sub.domain.tld.txt I came across this solution due to some multi website projects based on TYPO3 CMS and Neos CMS.


2

I had a similar problem where I want to distribute a web app that behaves as you describe: there are a bunch of static files in a specific directory that can be accessed as if they are on the web-app root (i.e. trying /images/pic.png get the image in public/images/pic.png) , and everything else gets mapped to a controller script. The first problem I ...


2

On Apache 2.4+ you can try putting the whole block of directives in an <If> block using an Apache Expression that tests the requested hostname. For example: <If "%{HTTP_HOST} == 'www-static.example.com'"> # : # Directives go here... # : </If> A few notes on your existing directives: <IfModule mod_headers.c> Header unset ETag ...


2

As has already been mentioned, the <Location> directive is not permitted in .htaccess files. If /foo/bar/ relates directly to a filesystem directory then you can place the .htaccess file in that directory to apply the directives (Header in this case) to that directory and below only. However, if /foo/bar/ is a URL-path only (which is also what the <...


2

-dns-ipv4-addr is only the address to be used for DNS requests. It's not used for the actual request. Try --interface instead: curl -XPOST https://example.com/test.php --interface aa.aa.aa.aa


2

You might be interested in the questions with the rewrite tag, since it contains many variations of your problem. Your Apache rewrite rule: RewriteRule ^(.*)$ /index.php/$1 [L] appends the entire request URI to /index.php. In nginx the path of the URI (normalized) is available in the $uri variable. If you need the query arguments too, you can use the $...


2

# Remove leading www, always using https regardless of the current URL scheme RewriteCond %{HTTP_HOST} ^w{2,4}.example.net(?::|$) [NC,NV] RewriteRule .* https://example.net%{REQUEST_URI} [L,R=301] # move http to https, except for dev.example.net RewriteCond %{HTTP:X-Forwarded-Proto} =http [NC,NV] RewriteCond %{HTTP_HOST} !^dev.example.net(?::|$) [NC,NV] ...


2

RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php?param1=$1&param2=$2 [QSA,L] How do you think $1 and $2 get set? You've not created any capturing groups in the RewriteRule pattern (which is a negated pattern so can't "match" anything anyway), so the $1 and $2 backreferences will indeed always be empty. Since you are using extensionless URLs that map ...


2

Try the following in the /v2/.htaccess file instead: Options +FollowSymLinks RewriteEngine On RewriteRule ^(\w+)/(\d+)/?$ $1/index.php?id=$2 [L] RewriteRule ^(\w+)/(\w+)/?$ $1/index.php?status=$2 [L] The "numeric" rule must be before the "string" rule to avoid conflicting. The "string" rule would otherwise win every time with the current regex. The first ...


2

how my shared hosting apache server chooses to return a 403 error. The 403 is triggered by mod_autoindex when formatted directory listings are disabled (the default) and no other response has already been served (eg. by mod_dir serving the DirectoryIndex / index document). The 403 is perhaps seen as the more appropriate response in this instance (rather ...


2

I believe it is a missing space character. Please change this: RewriteCond %{HTTP_HOST} ^example\.com$[OR] to this: RewriteCond %{HTTP_HOST} ^example\.com$ [OR] Your logfile entries proved that http://www.example.com was successfully rewritten to https://www.example.com/. They didn't prove anything about http://example.com. Adding the space character ...


2

tl;dr To check to see whether oldsite.com is still being requested, you should check your server access logs. (Maintain a separate log, just for oldsite.com.) How can I tell my .htaccess to set the http_referrer to www.oldsite.com You can't. The Referer HTTP request header is set by the User-Agent / browser. And the redirect itself is not a referrer. ...


2

The OPTIONS * with a wildcard refers to the entire server, whereas the .htaccess file equals <Directory> configuration section. If you want to disallow these requests, you'd need to move your directives from .htaccess to <VirtualHost> or global server configuration. BTW, Debian 9 comes with Apache 2.4, which has different access control ...


2

The Access Control has changed in Apache 2.4 you are using, and the changes are probably best explained in the Upgrading to 2.4 from 2.2. In short, from mod_access_compat: Compatibility: Available in Apache HTTP Server 2.3 as a compatibility module with previous versions of Apache httpd 2.x. The directives provided by this module have been deprecated ...


2

The Directory directive doesn't work on .htaccess context, but on server config or virtual host context. Either you place the configuration on server/vhost configuration or place an .htaccess file in that exact directory.


2

You don't need .htaccess with Apache, and it's actually only recommended as a last resort. Likewise, mod_rewrite should only be used if necessary: When not to use mod_rewrite. You can use both Redirect and RedirectMatch from mod_alias to return 404: Redirect 404 /config.php RedirectMatch 404 ^/config.php$ You can place them directly in your server ...


2

This would appear to be a bug in earlier versions of Apache 2.4 that was reportedly fixed in Apache 2.4.20 https://bz.apache.org/bugzilla/show_bug.cgi?id=58528 The bug would seem to be that when explicitly setting AllowOverrideList None the value is not being correctly reset. I have verified that I see the same (incorrect) behaviour in Apache 2.4.7 If you ...


2

The reason http://www.example.com/ is working and https://www.example.com/doesnotexist.html isn't is because your rewrite condition explicitly disables the rewriting if the client is accessing the site via HTTPS (which I believe several major browsers do by default now, but I don't have a source for this right off the top of my head). I'm assuming you did ...


2

Securing Apache is a large topic. See the section "The A" in this answer for some pointers. Your last 3 log messages are attempts at path traversal, to read files outside of the web root on your host. Protect Server Files by Default in the Apache security docs recommends that you deny access to all files by default: <Directory "/"> ...


1

You can't use <Directory> containers in .htaccess files. (The .htaccess file itself is essentially a directory container and directory containers cannot be nested.) Assuming you're on Apache 2.4 and /website1 and /website2 appear as part of the requested URL-path, then you can use an Apache Expression. For example: <If "%{REQUEST_URI} =~ m#^/(...


1

I assume you must be referring to the userinfo part of the URL in which the user credentials are passed, not "URL parameters" (which are part of the query-string): https://<userinfo>@example.com/foo?<query-string> As with any character that is not permitted in any one part of the URL (because it may have special meaning), it must be URL-encoded ...


1

1) A request to http://www.example.net will have two redirects. This can be resolved by simply reversing the two rules. Then www.example.net is redirected to HTTPS in the first redirect, so the HTTP to HTTPS redirect does not need to trigger. (This does, however, assume you have no intention of implementing HSTS - in which case you would need to keep them ...


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