Preserve HTTP/HTTPS protocol in .htaccess redirects
The trick provided by Jon is a nice hack, but I am afraid it could break if you want to use more [OR] conditions, and if you use more backreferences you have to be careful which number to use (%1 or...
View ArticleReference capture groups of multiple RewriteCond in RewriteRule
You could try constructing the target URL inside the rewrite conditions: RewriteCond ##%{QUERY_STRING} (.*)##(|.*&)param1=([^&]+) RewriteCond %1/%3##%{QUERY_STRING}...
View ArticleExclude folder from htaccess
You could also put a new .htaccess file in the folder you want to ignore, saying: RewriteEngine Off
View ArticleMake web root folder a sub-folder with .htaccess?
If you don’t have access to your host configuration DocumentRoot can only be used in server and virtual host configs, .htaccess it must be. Let’s add directives in your .htaccess RewriteEngine on I...
View ArticleUsing regular expression in htaccess for 301 redirects
Using mod_alias: RedirectMatch 301 ^/news/(.+?)(-[0-9]+)?$ /blog/$1 or using mod_rewrite: RewriteEngine On RewriteRule ^news/(.+?)(-[0-9]+)?$ /blog/$1 [L,R=301]
View Article.htaccess rewrite URL with a question mark “?”
You need to use %{QUERY_STRING} to capture the query string data: RewriteCond %{QUERY_STRING} ^view=(.*)$ RewriteRule ^component/users/?$ %1.html? [R=301,L] The above rule/condition will take the...
View ArticleRedirect all http AND https non-www URLS to https://www.xyz.com via htaccess
This is very much possible. use the following code. this works for me. RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L] RewriteCond %{HTTPS} off...
View ArticleForce a file or image to download using .htaccess
Put this into your .htaccess <FilesMatch "\.(?i:jpg|gif|png)$"> Header set Content-Disposition attachment </FilesMatch> Make sure you have mod_headers installed and enabled.
View Article.htaccess redirect to all IP’s but mine
You could do it with mod_rewrite Options +FollowSymlinks RewriteEngine on RewriteCond %{REMOTE_ADDR} !=123.45.67.89 RewriteRule index.php$ /construction.php [R=301,L]
View ArticleHow can I fix the ‘Missing Cross-Origin Resource Sharing (CORS) Response...
If you are just interested in the use of Access-Control-Allow-Origin:* You can do that with this .htaccess file at the site root. Header set Access-Control-Allow-Origin "*" Some useful information...
View Article