I want to redirect the subfolder and allcontents to root domain.
For example:
http://www.example.com/ubb/ will redirect to http://www.example.com
I put the .htaccess on ubb folder and the code is:
RewriteEngine On
RewriteRule ^.*$ / [R=302,L]
However when you access http://www.example.com/ubb/threads.php it will redirect to http://www.example.com/threads.php it should be http://www.example.com
Is there any code to try or other possible solution?
Place this rule in /ubb/.htaccess:
RewriteEngine On
RewriteBase /ubb/
RewriteRule ^ /? [R=302,L]
Also test it out in a different browser to avoid existing browser caches.
It's achievable using PHP which will be quiet easier I believe.
Create index.php inside ubb folder & add this code to it.
index.php
<?php
header('Location: http://www.example.com/');
?>
It'll redirect all request coming to www.example.com.
Related
https://example.com/app1
This is my subdirectory and it has one index.html file running on apache server.
I need to redirect all the requests to this directory like https://example.com/app1/* to https://example.com/app1 without changing the URL.
If user access to https://example.com/app1/test it should be redirected to https://example.com/app1 but URL should remain same as
https://example.com/app1/test
You can use this rule in your public_html/. htaccess :
RewriteEngine on
RewriteRule ^app1/((?!index\.html).+)$ /app1/ [NC,L]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]*)$ index.php [nc,qsa]
This one worked for me.
Thanks to all.
I actually have PHP code for making 301 redirect on my site.Previously i done this by putting that PHP code on \public_html\site_name\index.php and that is not the same in www\site_name\index
(\public_html and \www are not same at that time).
But now these two folders(public_html and www) are showing the same content.Then now where i need to put the code?how to achieve 301 redirect using PHP when the *\public_html* and \www folders are in same.
Give this a try, put this in your htaccess in the root of your site.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
replace example.com with your domain.
Create a .htaccess file in each of the directories with the folowing statement
Redirect 301 / http://anyothersite.com/
On my site www.apptic.me I used to have a redirect rule to always redirect index.php to the domain root.
I realized that this made the mobile layouts at the bottom here and here lose the "index.php" portion of the URL and PHP was no longer able to read the GET variables.
So I deleted the redirect. But now when users navigate to plain old www.apptic.me/index.php the "index.php" stays. I want to redirect index.php to the root if there are no GET variables.
Is this possible and how would I go about doing this?
Place this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\s [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
PHP can still read the $_GET variables even with redirection so there is no longer any problem with redirection.
In my site root directory. there are donghua.php and index.php. now, is there a way to use .htaccess file to let the visitor access my site .the default shows example.com/donghua.php. not example.com/index.php. thank you. the server is Apache.
ps:The user still can access example.com/index.php
i using DirectoryIndex donghua.php in the .htaccess. the default page is ok. but when i access example.com/index.php it redirect to example.com/donghua.php. if i forbid it redirect how do i do?
If you have access to the virtual host config file (or you should even be able to do this in htaccess) you can set the DirectoryIndex to be donghua.php if you want, i.e. instead of something like this:
DirectoryIndex index.html index.php default.html
Just do:
DirectoryIndex donghua.php
So whenever someone goes to your website, example.com, your apache installation will read donghua.php as the default index file.
Change your redirection rule in .htaccess file for index.php. If you open the .htaccess file, you can find the follwing lines,
RewriteCond %{THE_REQUEST} ^.*/example.php
RewriteRule ^(.*)example.php$ http://www.test.com/$1 [R=301,L]
Change or remove this rule for index.php. Better remove or comment it then it won't redirect to another page
"RewriteCond" this code check the codition if the browser requesting the file name index.php. If the condition is satisfy, then the next line will execute that is "RewriteRule". This "RewriteRule" will redirect your URL.
Search and find the name "index.php" in .htaccess file. comment out that lines. syntax to comment is "#".
Example:
#RewriteCond
#RewriteRule
Take back up before changing anything in .htaccess file.
To make your URL lovely and suitable for search engine ranking.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]
To redirect
redirect 301 /old-page.php http://www.yoursite.com/new-page.php
I wan't to redirect
www.site123.com/images/folder01/img01.jpg
to
www.site456.com/images/folder02/img01.jpg
I want to redirect the folder to folder separately. One line for each folder.
Entering in:
www.site123.com/images/folder01/sub01/sub02/999.xyz
Should be redirected (301) to:
www.site456.com/images/folder01/sub01/sub02/999.xyz
Since the directory structure from site123 to site456 look identical, have you tried the following global redirect?
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.site456.com/$1 [R=301,L]
If directory/specific then change your rule to something like this:
RewriteRule ^/folder/(.*) http://www.site456.com/folder/$1 [R=301,L]
If you want sub-folders too:
RewriteRule ^Images/?(.*) http://www.site456.com/Images/$1 [R=301,L]
Create a line for each pattern you wish to match and change the corresponding redirect URL/folder path. With rewrites it's sometimes trial/error too so take this and try it, then tweak as needed.