I would like to redirect all requests given to my server that contains the string 'track/' to a pdf file ubicated in the same path as the requested uri.
URL: http://www.whatever.com/track/Adelanto
RewriteRule ^/?track/(.*)$ track/Adelanto/file.pdf
This is hardcoded for this example. I would like to have this dynamic. Thanks.
You need to write this rule in your htaccess file
RewriteCond %{REQUEST_URI} ^(/track/)(.*)$ [NC]
RewriteCond %{REQUEST_URI} !\.pdf$ [NC]
RewriteRule ^ %{REQUEST_URI}/file.pdf [L,QSA,R]
You can see the htaccess file I have created for you here (https://htaccess.madewithlove.be?share=9ae812dd-54f6-596a-8b43-2ce1e8042e05)
Cheers
Related
I want redirect url to other url in the my website.
staging.mydomain.com/pathurl/
to this one :
staging.mydomain.com/newpathrul/
and I tried to add in httaccess file in my root project folder with this code :
RewriteCond %{HTTP_HOST} staging.mydomain.com/pathurl/ [NC]
RewriteRule ^/?$ "staging.mydomain.com/newpathrul/" [R=301,L]
but it's not work, could you tell what the correct htaccess code to redirect specified url with path to other url.
The HTTP_HOST Variable only has the host part, but does not have the path part.
RewriteCond %{HTTP_HOST} ^staging.mydomain.com$ [NC]
RewriteRule ^pathurl/(.*)$ /newpathurl/$1 [R=301,NC,L]
I am new to .htaccess redirect.
I have a source URL with too many parameters query string.
Source
http://localhost/se/karriar/?utm_source=A_candy_box&utm_medium=Printed_media&
utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&
utm_campaign=Mint_pastille_campaign
Target: http://www.sample-website.com
When I tried to call source URL its getting redirected along with query string as like below.
http://www.sample-website.com?utm_source=A_candy_box&utm_medium=Printed_media&
utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&
utm_campaign=Mint_pastille_campaign
I have written the below script in .htaccess file.
RewriteCond %{HTTP_HOST} ^(www.)?localhost$ [NC]
RewriteCond %{QUERY_STRING} ^utm_source=A_candy_box&utm_medium=Printed_media&utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&utm_campaign=Mint_pastille_campaign$ [NC]
RewriteRule ^se/karriar(.*)$ http://www.sample-website.com [R=301,L,NC] `
I would like to not appending query strings in the targeted URL. Can you any one help me?
Replace your .htaccess with this
RewriteCond %{HTTP_HOST} ^(www.)?localhost$ [NC]
RewriteCond %{QUERY_STRING} ^utm_source=A_candy_box&utm_medium=Printed_media&utm_term=2013&utm_content=Want_a_fresh_start_to_your_career%3F&utm_campaign=Mint_pastille_campaign$ [NC]
RewriteRule ^se/karriar(.*)$ http://www.sample-website.com? [R=301,L,NC]
Append ? after your target domain.
I have a url below:
http://www.mysite.com/mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price=
if PropertyBuyRent=rent and all other variables are empty then url should be like:
http://www.mysite.com/mypage.php/TimeshareForRent/All
how can i write htaccess for this?
You can use this rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(testing/mypage\.php)\?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [NC]
RewriteRule ^ /%1/TimeshareForRent/All? [R=301,L]
RewriteRule ^(testing/mypage.php)/TimeshareForRent/All/?$ /$1?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [L,NC,QSA]
Reference: Apache mod_rewrite Introduction
You can use this line and make edits in php file as follows
RewriteRule ^mypage.php/TimeshareForRent/All/?$ mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [L,NC,QSA]
You can tell your php file to redirect to "mypage.php/TimeshareForRent/All" when your condition matched, because with above rule, it will mask the url of variables with the one without variable
What I am trying to do is be able to point something like username.domain.com to index.php?url=username. I have been browsing around Google/StackOveflow and have not been able to find anything that will benefit me.
Best Regards.
Add these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com$ [NC]
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^ /index.php?url=%1 [L]
The first condition makes sure the requested host isn't www.domain.com or domain.com, the next line matches and groups the subdomain name, and the rule itself rewrites everything to /index.php with a query string url and the subdomain (backreferenced using %1).
I have a domain name with wildcard dns active. what i want to write in htaccess is that when the user type abc.domain.com/news/news-details.php then it should send request to the file news.php with arguments val=abc.
I have in the htaccess the following code:
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com
RewriteCond %{REQUEST_URI} ^news/news-details\.php$
#RewriteCond %{QUERY_STRING} !^id=.
RewriteRule (.*) /news.php?div=%1 [L]
But this is throwing a 404 error. what is the core part are the following two lines to explain
request for www.domain.com/news/news-details.php goes to www.domain.com/news.php
and abc.domain.com/news/news-details.php goes like www.domain.com/news.php?val=abc
Please note that i am not redirecting. the urls will show as a dynamic sub domain. physically there will be no folder. all files are located in the root.
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC]
RewriteCond %{HTTP_HOST) !^www\.
RewriteRule ^news/news-details.php$ /news.php?div=%1 [NC,QSA,L]