How to Redirect file to another path - .htaccess

I am trying to redirect https://example.com/sitemap.xml to https://example.com/sites/default/files/sitemap/sitemap.xml
How can I do so? I tried following rule but it is not working
RewriteRule ^(.*)\.xml$ /sites/default/files/sitemap/$1 [NC L]

Works for me!
RewriteRule ^([^/]+.xml)$ sites/default/files/sitemap/$1 [NC,L]

Related

RewriteRule for exact folder name with htaccess

Please help me on the RewriteRule below. I want to show the v3.php file for https://example.org/signup.
# Turn Rewrite Engine On
RewriteEngine on
# Rewrite for signup
RewriteRule ^signup v3.php [NC,L]
Works. But all other requests after /signup like /signups or https://example.org/signup/example/whatever show the v3.php as well. I need that RewriteRule only for that exact folder name.
Thanks for your help!
RewriteRule ^signup/?$ v3.php [NC,L]
Thank you, #anubhava

htaccess: Rewrite with several variables

I want to redirect a page like
/topic/italian-page2.html to /index.php?s=italien$p=2
or
/topic/france-page4.html to /index.php?s=france$p=4
but also (without page number)
/topic/spain.html to /index.php?s=spain$p=1
Right now I use
RewriteRule ^topic/([a-zA-Z0-9\-]+).html$ /index.php?s=$1&p=1 [L]
RewriteRule ^topic/([a-zA-Z0-9\-]+)-page([0-9]+).html$ /index.php?s=$1&p=$2 [L]
The first one (without page) works fine.
The second one doesn't.
It redirects to /index.php?s=italian-page2&p=$2
What did I do wrong? Where is my mistake?
Thank you!
Found a solution:
RewriteRule ^topic/([a-zA-Z0-9]*)-page([0-9]*).html$ /?s=$1&p=$2 [L]
RewriteRule ^topic/([a-zA-Z0-9\-]+).html$ /?s=$1&p=1 [L]
That works!

.htaccess rewrite URL with additional question mark “?”

With .htaccess i can't get working such link:
/quiz/results/solution-one/?email=myemail#domain.com
into
/results.php?level=4&email=myemail#domain.com
(solution-one should turn into level=4)
I have spend a few hours building .htaccess code:
Rewriterule ^quiz\/results\/solution-one/(.*)/?$ /var/www/domain.com/public_html/results.php?level=4$1 [QSA,L]
Or this one:
Rewriterule ^quiz\/results\/solution-one/([=#.a-zA-Z-]*) /var/www/domain.com/public_html/results.php?level=4&$1 [QSA,L]
But it doesn't work.
Thanks in advance!
Try with:
RewriteEngine on
Rewriterule ^quiz/results/solution-one/?$ results.php?level=4 [NC,QSA,L]
Without file path, but relative to root. And without test for query string (not part of Rewriterule test uri)

htaccess RewriteRule redirecting for URL's without trailing slashes

I have this snippet in my .htaccess file to defend against anyone trying to get into the app directory.
RewriteCond %{REQUEST_URI} ^/app.*$
RewriteRule ^(.*[^/])/?$ index.php?r=$1 [L,QSA]
And although it works when I go to http://domain/app/, if I make a request to http://domain/app, it redirects to http://domain/app/?r=app.
Does anyone know what needs to be changed to stop such redirection?
Try the DirectorySlash directive that can be use globally or per directory.
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryslash
try using
[L]
instead of
[L,QSA]

.htaccess redirecting dynamic URL

I am using the following code to attempt to redirect a dynamic URL to a new dynamic URL, under the same domain:
RewriteRule ^products/item/^\d([^/]+) /product/$1/ [R=301,L]
I've tried these too:
RewriteRule ^products/item/[^\d]([^/]+) /product/$1/ [R=301,L]
RewriteRule ^products/item/[0-9]([^/]+) /product/$1/ [R=301,L]
But this was redirecting /products/item/342/ to /product/42/, I tested this on a larger number (e.g. 123456789) and it redirected to /product/23456789/.
It would appear that my rule is not picking up the firsts digit, can anyone help me resolve this?
I've also tried using [\d] instaled of [0-9], but this has the same problem.
Cheers!
Try
RewriteRule ^products/item/(\d[^/]+) /product/$1/ [R=301,L]
RewriteRule ^products/item/([0-9]+) /product/$1/ [R=301,L]

Resources