This is our 1st attempt with .htaccess scription. Please help us with the below requirement:
Actual URL:
https://domaina.com/Criteria1/valueaddedcourse/2202223742-first aid course.pdf
If the URL Contains "/Criteria1/valueaddedcourse/" then it should redirect to a new domain & path but with same file name (2202223742-first aid course.pdf)
https://qaanr.s3-ap-south-1.amazonaws.com/2202223742-first aid course.pdf
Being a newbie, find apache tutorial too cryptic (https://httpd.apache.org/docs/2.4/howto/htaccess.html)
Please do share content with details description for .htaccess - this will help us to learn.
==== Update to above question ===
this code works for me:
`
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/Criteria1/valueaddedcourse/
RewriteRule ^(.*) https://qaanr.s3-ap-south-1.amazonaws.com/% {REQUEST_FILENAME} [P]
`
this code works for redirection, Fails to mask. Browser has to show the original domain name & not https://qaanr.s3-ap-south-1.amazonaws.com/
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/Criteria1/valueaddedcourse/
RewriteRule ^(.*)$ https://qaanr.s3-ap-south-1.amazonaws.com/$1 [R=301,L]
Usage = If the URL Contains "/Criteria1/valueaddedcourse/" then it will redirect to a new domain & path but with same file name (2202223742-first aid course.pdf)
Related
I have website1.com setup so that when users visit website1.com they get redirected via a meta tag in an index.html to website1.com/directory
Then they use the website and go to links such as website1.com/directory/index.html or what ever. I am trying to hide the "directory" in the link so that users only see website1.com/index.html
I have place the htaccess which is to rewrite the url to website1.com/index.html at website1.com/directory/.htaccess
I am not doing anything else special and this should be an easy task. My current exact htaccess is as follows:
RewriteEngine On
RewriteCondition %{REQUEST_URI} !^directory/
RewriteRule ^(.*)$ directory/$1 [L]
Should be easy right..... All I get is a 404
In my server I have Mod_Rewrite & mod security and suspect one of them is causing this not to work but can't imagine why. Am I missing something here?
Your rule is incorrect since %{REQUEST_URI} variable has starting /
You need to place this in document root
Use this code in document root .htaccess:
RewriteEngine On
RewriteCondition %{REQUEST_URI} !^/directory/
RewriteRule ^(.*)$ /directory/$1 [L]
I am looking for a script to convert short domain link to main domain URL such as the below example? It's like Facebook.com/username , it will automatically redirect you to the complete URL www.facebook.com/username
When user type short domain = http://abc.com/leon
the system should automatically CONVERT IT TO main domain URL = http://www.abc.com/leon
Do i need to edit any on the .htaccess? If so, what is the script should i add?
I have tried the following script on .htaccess , but it doesn't convert to main URL
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^([a-zA-Z]+)$ /Test.php?pname=$1 [L,QSA]
Please help.
Cheers
Alright... Identified this may be under the category of DNS issue and found this link => Best way to redirect non-www to www? ; as well the following script seem work
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.youraddress.com$ [NC]
RewriteRule ^(.*)$ http://www.youraddress.com/$1 [R=301,L]
How can I use htaccess to always ADD a directory immediately after the domain name?
So for example, change requests for
http://domain.com/path-to/file.php
to
http://domain.com/added-directory/path-to/file.php
The context here is that i am migrating a site to a new server, and the domain name is not yet pointed to the new server. But the hosting company provides me with a "temporary url" based on the Shared IP and my account username, so http://216.172.172.211/~myusername/ , but all the paths in all the html are doc-root relative, like /images/logo.png, which translates to http://216.172.172.211/images/logo.png which is wrong. I need it to be http://216.172.172.211/~myusername/images/logo.png .
try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/~myusername
RewriteRule ^(.*)$ /~myusername/$1 [L]
If you want to redirect so that URLs show the ~myusername part in the URL address bar, add an R flag to the square brackets:
RewriteRule ^(.*)$ /~myusername/$1 [L,R=301]
This worked for me perfectly
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/~gye
RewriteRule ^(.*)$ https://%{HTTP_HOST}/gye/$1 [R=301,L]
If an URL comes without the /XYZ
Add https:// at the beginning and /gye/ after the domain.
Testing here really helped: https://htaccess.madewithlove.be/
----EDIT---
I have just realized that my explanation of the problem was missing an important piece of information.
The URL's should only be redirected if second parameter is present.
So the rule should read:
Redirect any URL that has /d/ in it, ONLY if /d2/ is also found in the URL.
----End Edit__
I have the need to 301 redirect all URL's on a site that contain a specific parameter to the same URL, but with an additional directory included. All of the URL's that require redirection contain a certain directory: /d/ Example:
http://www.mysite.com/category1/d/subcategory1/subdirectory2/
--Should Redirect to --
http://www.mysite.com/newdirectory/category1/d/subcategory1/subdirectory2/
The one thing in common with any of the URLs' requiring redirection is that they all contain a directory /d/ in the URL, which always immediately follows the "category" directory as indicated in bold in sample URL's above. I would then like to insert an additional directory in front of the category directory as indicated in bold in the sample URL's above. The rest of the URL will remain the same.
Can anyone help with this? I'm relatively new to mod_rewrite and realize I can make a big mess if I don't get it right.
Thanks in advance for anyone who can offer hlep
:)
Try this (edited to reflect change in question):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*/d/.* [NC]
RewriteCond %{REQUEST_URI} ^.*/d2/.* [NC]
RewriteCond %{REQUEST_URI} !/newdirectory/ [NC]
RewriteRule ^(.*)/d/(.*)$ http://www.mysite.com/newdirectory/$1/d/$2 [R=301,L]
Try adding the following to your htaccess file in the root directory of your site.
RewriteEngine On
RewriteBase /
#if the url contains a /d2/ [NC]
RewriteCond %{REQUEST_URI} /d2/ [NC]
RewriteRule ^([-a-zA-Z0-9]+/d/[-a-zA-Z0-9]+/[-a-zA-Z0-9]+/)$ /newdirectory/$1 [L,R,NC]
I am writing a multi language website. Therefore I would like some help with a URL rewrite problem.
Case:
When someone visits www.example.com without adding a country code (nl, en, de) the htaccess redirects the visitor to www.example.com/nl/ i.g.
RewriteRule !(nl|en|de)(.*).* /nl/ [R=301,L]
The website is renewed and has got many url's directing to the website (google, forums). i.g. www.example.com/oldpage-nomore.html. What I would like is the following; the htaccess should detect that the request uri doesn't contain nl,en or de and should redirect to pagenotfound.php. RewriteRule ^(.*)\.html /public/oldurl?section=nl¬found=$1$2&basehref=true&%1 [PT,L] the problem with this Rewrite rule is: all files ending in .html are being redirected.
What I am looking for is the following:
When someone visits www.example.com and no request uri is entered this should redirect to www.example.com/nl/
When there is a requested uri and this doens't contain a countrycode (nl|en|de) than redirect to pagenotfound.php
I tried the following but it doens't work:
RewriteCond %{REQUEST_URI} !^(nl|en|de)$
RewriteRule ^([a-z]{2})/(.*)\.html$ /pagenotfound.php?page=$2 [L,R=404]
I hope someone can help.
Thank you in advance.
Try to place this .htaccess file at the server root folder:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^.*$ /nl/ [R]
RewriteCond %{REQUEST_URI} !^/(nl|en|de)
RewriteRule ^.*/(.*)\.html$ /pagenotfound.php?page=$2 [L,R=404]
(you probably made several mistakes, I tried to fix them)
I'm not sure with the first RewriteCond %{REQUEST_URI} regular expression - maybe remove the question mark or slash, I don't now... can't test now.