how to convert exrenal link to internal using .htaccess? - .htaccess

i want convert all external link to internal and redirect them
let me show you what i want:
i have an external link to my website like this:
link
and i converted it to:
link
OR
link
OR somthing like this
how can i use .htaccess to make sure when someone opened the link he goes to:
https://external.com/some text here
i tried this but id didn't worked
RewriteEngine On
RewriteRule ^mywebsite.com/redirect/(.*)$ /$1 [NC,L]

RewriteRule ^mywebsite.com/redirect/(.*)$ /$1 [NC,L]
RewriteRule only matches against the path component of the URL. (And when configured in .htaccess context, the path it checks against never starts with a leading slash, the path to the current directory has been stripped off at this point already.)
/$1 would cause a slash before the actual substitution URL.
Both fixed, it should simply look like this:
RewriteRule ^redirect/(.*)$ $1 [L]

Related

Rewrite A Filename To Another Filename Via .htaccess

I wanna change "announcements.php" to "blog.php" in the url. Individual article's are identified by id=x, such as"annoucements.php?id=1", which I will need it to say "blog.php?id=1".
I tried:
RewriteRule ^announcements.php ./blog.php
Try with:
RewriteEngine on
RewriteRule ^announcements\.php /blog.php [NC,L]
If you change the file name in the url, you do a redirection, not a rewrite.

.htaccess rewrite is not working

I want to change the URL of my site:
http://example.com/clinicdetails.php?url=/diet-clinic-in-punjabi-bagh.html
to look like this:
http://example.com/clinicdetails.php/diet-clinic-in-punjabi-bagh.html
My code in .htaccess file is as follows:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /clinicdetails.php?url=$1 [L]
However, this is not working (no error) on my localhost and also not on the shared hosting servers. What could be the issue here?
RewriteRule ^([^/]*)\.html$ /clinicdetails.php?url=$1 [L]
The RewriteRule pattern is failing to match the given URL because of the start of string anchor ^. Whilst you don't have slashes in the path segment you are trying to match, you do in the rest of the URL. So, try the following:
RewriteRule ([^/]+)\.html$ /clinicdetails.php?url=/$1 [L]
I've also changed the * to +, since the filename is at least 1 char. A more specific regex is better.
To map to your desired URL, you would also seem to require a slash prefix on the URL param value. ie. url=/$1

Simple rewrite if a word is present in a url

I have about 100 urls which are like these:
http://example.com/en/contact-us
http://example.com/en/about-us
When the someone clicks on any of them, it should the same page but with a parameter that has been appended
for example :
http://example.com/en/contact-us?language=en
How would i go to solve this? I am tring to write something generic that will do the job for the 100 urls i have.
This is what i have got :
RewriteCond %{REQUEST_URI} /en/ [NC]
RewriteRule ^ %{REQUEST_URI}/?language=en
Internal redirection: URL in the browser doesn't change
RewriteEngine on
RewriteRule ^/?([a-z]+)/([^/]+)/? $1/$2?language=$1 [L]
External redirection: URL in the browser changes to new URL
RewriteEngine on
RewriteRule ^/?([a-z]+)/([^/]+)/? $1/$2?language=$1 [R=301,L]
Please try this
I think you may have forgotten to put a .php file extension at the end?
This will match any two-letter language folder followed by another directory, as long as there is no period.
RewriteRule ^/(\w\w)/([^/]+)/?$ $1/$2.php?language=$1
Be sure to test it with your URLs at regex101.

How to write a htaccess to change url but point to actual path internally using regex match

url = www.example.com/de/abc
I just want to change fix url word 'abc' into fix word 'xyz' for browser compatibility only changed url show in browser. But change url point to actual directory path means
www.example.com/de/xyz will follow internally www.example.com/de/abc.
I used some regex to do this, but not able to get actual solution
How can I do this.
Thanks in advance
Code from comment :
RewriteCond %{REQUEST_URI} ^/de/advertiseWithUs$ [NC]
RewriteRule ^(.*) /de/unsere-tipps [R=302,L]
If I have correctly understood what you want, here a solution you can try :
RewriteRule ^de/advertiseWithUs$ http://yourdomain.com/de/unsere-tipps [R=302,NC,L]
RewriteRule ^de/unsere-tipps$ de/advertiseWithUs [NC,L]
The first rule change URL (with a 302 redirection), the second one make the internal redirection to point to the right page.

Need to .htaccess redirect path with a variable URI segmant to another directory without changing URL

My current .htaccess looks like this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^[0-9]+/pos /pos/$1 [L]
Currently this will redirect a url such as example.com/234234234/pos to example.com/pos
I would like it to load the directory example.com/pos, but without losing the original URL (example.com/234234234/pos) from the address bar.
Basically, the number listed in the url can change, but I always want it to load the same path.
This rule doesn't look right:
RewriteRule ^[0-9]+/pos /pos/$1 [L]
As you're not capturing anything hence there is no $1. If you want to ignore any number before /pos then use this rule:
RewriteRule ^[0-9]+/(pos)/?$ /$1 [L,NC]
Thank you anubhava. Part of your answer helped me. I did want the numbers ignored, but didn't want them to disappear.
This is the line I needed:
RewriteRule ^[0-9]+/pos/ /pos/ [L,NC]
Did not need to capture anything at all. That is what was causing the redirect.

Resources