Remove folder to URL with querystrings - .htaccess

I have a URL, that in the past. It was accessed as in the example below http://example.com.br/blog but today its as example.com.br.
However, I have external access to queries strings pointing to the folder:
example.com.br/blog/?utm_source=mkt&utm_medium=email&utm_campaign...etc
I want all requests to remove the folder:
example.com.br/?utm_source=mkt&utm_medium=email&utm_campaign...etc
What rules should I create in the .htaccess file?

You can use:
RewriteEngine on
RewriteRule ^blog/?$ / [L,NC,R=301]
The query string does not change

Related

htaccess redirect from folder with subdirectory to single path directoy

Previously my site was in wordpress, now converted into html.
I have 500+ pdfs that needs to redirect from
mysite.com/wp-content/themes/my-theme/pdfs folder to mysite.com/pdf/
Do you have server-level access to the site? If so I would create a symbolic link in the public root directory of your website to wp-content/themes/my-theme/pdfs and call it pdf.
If all you can do is .htaccess, then you can create a file like this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^pdf/(.*)$ /wp-content/themes/my-theme/pdfs /$1 [R=301,NC,L]
You might check out a great tutorial on rewrite rules.
I tried like this it works for me.
RewriteRule ^wp-content/themes/my-theme/pdfs/(.*)$ /pdf/$1 [R=301,NC,L]

.htaccess execute file from different location

I've got a URL structure where there's a gallery page at /worcester/gallery which has an index.php file within. What I want is to have all child URLs of this, like /worcester/gallery/last-night to run the index.php file within /worcester/gallery.
I'm not looking to redirect the URL, I want to keep the URL as it is, I'll be using that to work out which gallery to get from index.php
Since you want to access the URI in php, you can simply put the following as .htaccess inside gallery/ directory:
RewriteEngine On
RewriteRule !^index\.php index.php [L]
I am not sure though, that REQUEST_URI will be available inside the index.php file. If it is, well and good; if it isn't, you can pass the rest of the URL as a GET parameter:
RewriteEngine On
RewriteRule ^((?!index\.php).+)$ index.php?uri=$1 [L]

Redirect URL with query string on same domain but different directory using htaccess

I am trying to redirect a page to another page along with query string.
Example:
The URL below
http://example.com/firstdir/?abc=xyz
needs to redirect to the below URL with same query string on same domain.
http://example.com/seconddir/?abc=xyz
When there are no query string added in the URL, it should stay on the same page and will not redirect.
I have tried to explain what I am looking for, please HELP !!!
tHANK YOU.
Just put your .htaccess in your root folder and it will handle recursive folders.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} .+
RewriteRule ^firstdir/?$ /seconddir [NC,L,R=302]
Query string is automatically carried over to target URL

How to redirect any folders within a subdirectory to a specific file using htaccess?

I want to redirect any folder to a specific php file with the folder name as variable using htaccess, for example:
www.domain.com/subdirectory/folder1 redirects to www.domain.com/subdirectory/file.php?id=folder1
www.domain.com/subdirectory/folder2 redirects to www.domain.com/subdirectory/file.php?id=folder2
This should work if the folders have "/" at their end, for example,
www.domain.com/subdirectory/folder3/ redirects to www.domain.com/subdirectory/file.php?id=folder3
It will be better if I can put the .htaccess file in the subdirectory and get redirect rule according to it.
I created a .htaccess file with the following code while putting the file in the subdirectory:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$ file.php?id=$1
but it does not work.
RewriteRule ^folder(.*)$ file.php?id=$1
use these i am not tested but it will be work.

.htaccess redirecting requests to the same folder

I want to use .htaccessto redirect different requests to the same folder.
E.g.:
domain.de/ordner1/fileX.html
domain.de/en/folder1/fileX.html
domain.de/it/casella1/fileX.html
So whenever something is requested out of /ordner1/, /folder1/ or /casella1/ I want .htaccess to fetch the requested file out of a specific directory like domain.de/all/fileX.html.
I want to prevent duplicate content but also keep the foldernames in the selected language.
Could you help me solve this problem?
Try adding the following to the .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
#skip css, js etc
RewriteCond %{REQUEST_URI} !\.(css|js)[NC]
#if request to ordner or folder1 or casella1, serve the file from all/
RewriteRule ^(ordner1|en/folder1|it/casella1)/(.+)$ all/$2 [L,NC]
In your docroot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^(ordner1/|en/folder1/|it/casella1/)(.*$) all/$2 [L]
You would need to add extra names to map other translation equivalents.

Resources