.htacces redirection for specific files - .htaccess

i know that there are a lot of questions about .htaccess, but i am not able to find the solution.
I have an index.php on a folder on my domain.
mydomain.com/folder/index.php
This index.php list 3 urls that i do not want the people to see, i only want them to be redirected to the first one.
I cannot modify the index.php file, i need to redirect the trafic using htaccess, this way:
I need to redirect everything that go to
mydomain.com/folder/
www.mydomain.com/folder/
mydomain.com/folder/index.php
www.mydomain.com/folder/index.php
and send them into this url
www.mydomain.com/folder/text
Any ideas?
Thank you very much

Related

Redirecting to a different directory with htaccess without changing URL

I would like to add some htaccess so that when a visitor goes to:
domain.com/xxx
They would see the content (without the URL changing) from
domain.com/yyy/zzz
Also any subcontent would show... like visiting
domain.com/xxx/inner-page
would show the content from:
domain.com/yyy/zzz/inner-page
I know that can be done, I just haven't figured out the htaccess code for it yet.
Here's the extra part I'm not sure can be done- sometimes those pages may have full URL links pointing to "/yyy/zzz/inner-page"
I would want anyone going to one of those pages to be redirected (changing the URL) to the equivalent "xxx" url... hopefully without causing a loop of too many redirects issue. Is that possible to do?
You may use this rule in site root .htaccess:
RewriteEngine On
RewriteRule ^xxx(/.*)?$ yyy/zzz$1 [L,NC]

.htaccess redirect to page within folder leads to repeating url segments

I'd like to do the reverse of this issue. I am trying to redirect users from a subfolder to a child page. This is my current rule that doesn't work:
Redirect 302 /boston /boston/info
Using this, if I go to example.com/boston, I get redirected to example.com/boston/info/info/info/info/info/info... and it keeps going.
I imagine I'll need to switch to a RewriteRule in order to prevent this duplication. How should I go about this?
"/boston/info" - This should be the full URL you are redirecting too.
eg. www.website.com/boston/info

Need to forward folder of 1000 pages

I am given the task of forwarding a folder of hundreds of URLs to a new folder name. The URL: "http://domain.com/old/1_of_1000_pages" to http://domain.com/new/1_of_1000_pages".
What is the best way to do this? Use .htaccess? I shouldn't write all of them individually, right? There might be 1,000. Is there a way to just forward everything going to /old/ to /new/ while still reaching the correct /1_of_1000_pages ?
I'm a web designer, but I'm not that familiar with .htaccess code yet!
Thank you ahead of time!!!
You can use this simple generic RedirectMatch rule to handle all URLs in your website root .htaccess:
RedirectMatch 301 ^/old/(.*)$ /new/$1

.htaccess Redirect Issue , struggling with parameters

I am struggling with an url/parameter issue.
The main index.php page of my website was previously used for e.g.
www.domain.com/index.php?site=3&word=21 and
www.domain.com/index.php?site=3
But now I have changed those things, but in Google the URLs are still listed. So what I need is to redirect all the type of pages above to the main page/domain www.domain.com.
I believe .htaccess redirect is the right thing to use then, is that correct?
What type of code do I need to redirect those to main domain. Just the url's with parameters after index.php? etc. not other directories e.g. www.domain.com/sunshine/
Would be great if someone could help me with this. I believe it is actually a quick fix, but I have failed to get the code correct.
Thanks.
You can add this to an .htaccess in your site root:
RedirectMatch permanent ^/index.php* http://www.domain.com/
But, be careful if your new index page is also named index.php because you might run into a redirect loop.

How can I redirect and then rewrite url in same file for pretty URL?

I have just been asked to migrate a site from one server to another for a site that I did not build. They have a lot of links to pages that dont exist.
<a href="app/batteries">
This is not actually a directory in the site, but there is an app.php file in the root directory. I have gotten it to display the products by redirecting anything to the app/ directory to app.php?app=. The value of ?app= is dynamic, so any solution would need to be dynamic. I have simply used the redirect statement in the htaccess file to get it to the app.php page. Is there a way to get the url back to the pretty url after a redirect?
Any help would be awesome. Thanks in advance.
You should use ModRewrite instead, for matching a pretty url with regexps, and converting into the url using the app.php.
The rewrite is local to the server, so the visitor sees only pretty urls.

Resources