5 votes

.htaccess - Redirect all URLs with one exception

As mod_alias is recommended for simple redirects, here's the solution with mod_alias: # Specific redirects: Redirect 301 /old-prefix https://www.example.com/ Redirect 301 /another-old-prefix/ https://...
  • 44.8k
4 votes
Accepted

.htaccess - Redirect all URLs with one exception

You are mixing mod_rewrite (RewriteCond, RewriteRule) and mod_alias (Redirect, RedirectMatch). The stray mod_rewrite RewriteCond directive will not do anything here. This directive only applies to the ...
  • 12.1k
4 votes
Accepted

seo friendly url not working

...my .htaccess file which lives in the distributor folder RewriteRule ^distributor/([0-9]+)$ distributor/index.php?id=$1 If the .htaccess file is actually inside the /distributor directory then you ...
  • 12.1k
2 votes

seo friendly url not working

Your RewriteRule matches only numbers, that is, distributor/3728 etc. It does not match abcinc. From the id argument passed to index.php it looks like your application expects an ID here and not a ...
2 votes

I'm in trouble with .htaccess RewriteRule

A number of different things: Don’t use .htaccess files There are numerous well-intended examples of code in .htaccess files that then get copied again and again by/for cargo cult system ...
  • 1,713
2 votes

Apache: How to "hide" a subdomain but serve over https

There's at least three ways to solve this: Use the DNS challenge, requiring no HTTP connection Disable basic auth for .well-known/-path which is used by certbot. Use the standalone module of certbot. ...
  • 5,784
2 votes

Redirect part of a URL parameter to the URL-Path

RewriteCond %{QUERY_STRING} ^create_account=([0-9]+)&back=([0-9]+)$ RewriteRule /login https://example.com/product/%1/? [L,R=301] This tries to match a back URL parameter whose value consists ...
  • 12.1k
1 vote
Accepted

how to redirect a web page based on domain name using .htaccess

The recommendation from the Apache project is: In general, you should only use .htaccess files when you don't have access to the main server configuration file. [In other words: your site is on ...
  • 74k
1 vote

Apache ToLower on all Wordpress pages (not PDF/CSS/JS)

RewriteRule ^/(.*)$ /${lc:$1} !^(pdf|js|css|png|jpg|jpeg|webp) You say this "doesn't have any effect", however, this is syntactically invalid ("bad flags argument") and should ...
  • 12.1k
1 vote
Accepted

Apache htaccess ruleset: Try request as: 1) file as-is 2) file + .html suffix 3) DirectoryIndex 4) Else to index.php CMS router

If there is no matching #3 DirectoryIndex then continue to #4 CMS You can't fail "gracefully" with mod_dir's DirectoryIndex to then do something else with the request using mod_rewrite (ie. ...
  • 12.1k
1 vote

RewriteCond rules from apache to nginx

nginx does not support such functionality in such direct way than Apache2. Specifically, nginx has no variable for "seconds", and it has no integer comparisons. You need to look into nginx ...
1 vote
Accepted

Condition depending on domain in .htaccess: SetEnvIf and IfDefine?

<IfDefine> is probably not supported by LiteSpeed, so it gets "ignored" and the contents is executed unconditionally (there may be something in the error log). On Apache <IfDefine&...
  • 12.1k
1 vote
Accepted

htaccess: 301 redirect defined URLs to new domain and catch all redirect the rest

Redirect is a mod_alias directive (nothing to do with RewriteEngine). RewriteRule belongs to mod_rewrite. mod_rewrite is always processed first, despite the apparent order of the directives in the ...
  • 12.1k
1 vote
Accepted

Redirect www to non www and redirect to index.php

From what you've stated in comments, there doesn't seem to be a requirement to maintain two separate .htaccess files. In this case it would be simpler to maintain just one .htaccess file in the ...
  • 12.1k
1 vote

How do I add the __Secure prefix in this .htaccess line?

ORIGINAL RESPONSE Does this give you the information you need: https://geekflare.com/httponly-secure-cookie-apache/ Implementation Procedure in Apache Ensure you have mod_headers.so enabled in ...
  • 26
1 vote

How can I remove 2 separate portions of a URL using mod_rewrite?

In the .htaccess file located in the subdirectory at /library/photography/.htaccess you can do something like the following using mod_rewrite to internally rewrite the request to the desired URL. ...
  • 12.1k
1 vote

How can I remove 2 separate portions of a URL using mod_rewrite?

I am not 100% sure this is the best way to do it, but given the following folder structure user@instance-apache:/var/www/html$ tree -a . ├── .htaccess ├── index.html └── library └── photography ...
  • 710
1 vote
Accepted

Apache mod_rewrite RewriteRule loops despite L flag

The L flag only stops the current pass through the rewrite engine, it does not stop all processing. The directives that follow are not processed immediately, but (in a directory context) the rewriting ...
  • 12.1k
1 vote
Accepted

Apache .htaccess if doesn't work with local assigned env vars

SetEnvIf maintenance 0 You have the syntax wrong... you are trying to use SetEnv (mod_env) syntax with the more complex SetEnvIf (mod_setenvif) directive. So, either use SetEnv: SetEnv maintenance 1 ...
  • 12.1k
1 vote
Accepted

Blocking Port 8080 from direct IP access but allow access via domain (Virtualhost Config)

Since you are reverse proxying to localhost:8080, there is probably some application server other than Apache listening on port 8080. You cannot control that other software by adding VirtualHost ...
  • 44.8k
1 vote
Accepted

Redirect to other server and domain if file not found

I got the solution after modifying @Rob answer. set $v_filename nf; location ~ ^/data/(.*)$ { try_files $uri @externalbackup; set $v_filename $1; } location @externalbackup { return ...
1 vote

Redirect to other server and domain if file not found

In nginx you would use a try_files directive, which serves the content from a local file, if it exists in one (or more) local directories. When no file is found, an internal redirect to the uri ...
  • 1,177
1 vote

.htaccess redirect sub-folders to the correspondent index.php

You just need to make sure that DirectoryIndex is set correctly in the root .htaccess file. (This defaults to index.html, although many distros include index.php as well, so you often don't need to do ...
  • 12.1k
1 vote
Accepted

On Apache how to switch off DirectorySlash only for requests to a specific subdomain?

By the sounds of it, your sub subdomain maps to the same directory as the main domain and all other subdomains (www and other, etc.) However, if all requests to the sub subdomain are internally ...
  • 12.1k
1 vote

Rewrite Performance, and rules that work in .htaccess but not vhost

Remember to add the leading slash Read the Apache documentation, especially the part about where you often don't need mod_rewrite for a lot of things (which can be handled with mod_alias): https://...
1 vote

.htaccess not working but is enabled

<Directory /> Options FollowSymLinks AllowOverride All You should never set AllowOverride All for the entire filesystem (ie. inside the <Directory /> container). This should be (and ...
  • 12.1k
1 vote

Does it matter in which order rules are placed in htaccess?

There is much more than "the order does matter" to this question. Apache has a complex processing algorithm of its config files - this may be surprising. Here is my understanding from what I'...
  • 111

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