HtAccess Rewrite Needed - .htaccess

My host will not allow me to change the default folder of my primary domain. I have managed to Rewrite http://www.mysite.com to the real folder
public_html/mysite.com/www/
with the following code:
RewriteEngine On
RewriteRule ^$ /mysite.com/www/ [R=301,L]
This does successfully load my domain from the subfolder, but the url becomes:
http://mysite.com/mysite.com/www/
How can I continue loading requests from http://mysite.com/index.html in the correct folder shown above, without showing it in the client-side url?

Try this one:
RewriteEngine On
RewriteRule ^mysite.com/www/(.*) - [L]
RewriteRule ^(.*)$ mysite.com/www/$1 [L]
UPD:
The line with the dash is required because after the redirect at line 3 Apache reads the .htaccess once again to process the redirected URL. The rule prevents infinite loop.

Try removing the R=301.

Related

redirect url from htaccess file

I'm trying to bulk redirect my site link like this,I need to remove home from every link and redirect it to root directory as shown below.
example.com/home/hello-world.
example.com/home/tag/world.
to
example.com/hello-world
example.com/tag/world.
I'm using these code
RewriteEngine On
RewriteCond %{REQUEST_URI} (.+)/home(.*)$
RewriteRule ^ %1/ [R=301,L]
Considering that your htaccess rules file have more rules apart from your shown ones, which will take care of handling pages from backend(rewrite), if this is the case then please try following htaccess rules file.
Please these rules at top of your htaccess rules file. Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /example.com/
RewriteRule ^home/(.*)$ /$1 [R=301,L]

SSL .htaccess - Simple Q

I truly hate this file... I just spent 6.5 hours trying to figure this out and with my ADHD dyslexia it's just impossible!!
I have a domain that I bought for SSL for (currently I Have to wait for the ssl for WWW to kick in but for now the domain without WWW works, for example:
https://tomas.com
The .htaccess I have in root is currently:
RewriteEngine On
RewriteCond %{HTTP_HOST} tomas\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://tomas.com/$1 [R,L]
And the code above does in fact activate SSL which is good. The thing is, I have a few files in root domain but one of them called is:
hello.php (located at: "tomas.com/hello.php")
If I go to:
http://tomas.com/hello
I want it to display that file (and in address bar it should say: "http://tomas.com/hello").
Before the SSL I had this code below and it worked (but not anymore):
RewriteRule ^([^/]*)/?(.*)$ $1.php
Any idea how the entire .htaccess is supposed to look like? :/
I'm also same time trying to FORCE it to NOT use www (so if they do it should be redirected to a non WWW url)
Thank you so much in advance!!!!!!!!!!!!
Before the SSL I had this code below and it worked (but not anymore):
RewriteRule ^([^/]*)/?(.*)$ $1.php
Not sure how this "worked" before, it's not complete by itself and does more that simply append a .php extension. You need something to prevent a rewrite loop, since hello.php also matches the pattern ^([^/]*)/?(.*)$.
Try the following instead, after your HTTP to HTTPS redirect.
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule (.*) $1.php [L]
This first checks that the file with a .php file extension exists before internally rewriting to it.
Alternatively, you could instead just enable MultiViews if you aren't doing any other URL rewriting. For example, at the top of your file:
Options +MultiViews
This uses mod_negotiation to basically enable extensionless URLs for everything!

.htaccess forward from one domain to a specific .html page

I know how to use .htaccess to forward everything in one domain to a new domain name. But in this case, I want everything from one domain to go to a specific .html page on a different domain. That's where I'm lost. I'm trying the following but it just redirects to a folder and the page in question is in that folder but obviously, I don't want people seeing the contents of that folder. Make any sense? So example.com needs to go to yyy.com/some-page.html
This is what I'm currently using:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule ^(.*)$ http://www.1.yyy.com/$1 [R=301,L]
Try:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule .* http://www.1.yyy.com/some-page.html [R,L]
You can also put a blank index.html page to the directory in question to mask its contents or
you can put index.php file with this code <? header ("location: http://www.1.yyy.com/some-page.html"); ?> that will redirect a user to the desired page.
$1 is a place holder for the 1st pattern match. So if you are rewriting domaina.com/someurl/, it is attempting to load domainb.com/someurl/. Swap the $1 with the actual page --- e.g. somepage.html and it should work. But unless both of these domains are pointing to the same files/directories, the rule seems a bit overcomplicated.
So how about just a simple redirect?
Try this in your .htaccess file.
redirect 301 / http://somesite.com/somepage.html
OR you can try this.
RewriteRule ^(.*)$ http://somesite.com/somepage.html [R=301,L]
It does work and you can test my RewriteRule below.
http://htaccess.madewithlove.be/
There must be something else going on.

Redirect /index.php from the end of the URL

Have a website with subpages all in this format:
mydomain.com/something
That's fine. But what is NOT fine is that you can also do mydomain.com/something/index.php (you can enter address in this format into your browser) and you still get the content on that mydomain.com/something.
I don't want those two possibilites to be available at the same time, Google doesn't like this. I want just one to be possible.
So what I want to do is whenever you type into your browser mydomain.com/something/index.php, you will be redirected to mydomain.com/something (without that /index.php at the end).
How should I write a .htaccess code to do something like this?
add the following lines to .htaccess in the root directory of your website
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.*?)/?index.php$ /$1 [R=301,L,NC,QSA]
Note: the first condition assure that no previous redirection is made (to prevent redirection loop)
Mordor:
You can try this in your .htaccess file:
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

modrewrite website with slash in .htaccess

How can I translate an URL like:
http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
to:
http://localhost/mySite/OFFERS/ARTICLE/DETAIL
if one parameter is empty it should still work like this:
localhost/mySite/?link=OFFERS&sublink=ARTICLE
localhost/mySite/OFFERS/ARTICLE
Extra problem: There is an enter page under index.php and the rewrite should work with index2.php. Best would be if it would work under localhost and on live system without changes.
Currently I'm using: RewriteRule ^([^/.]+)$ index2.php?link=$1 [L]
But that only works for one parameter and I couldn't improve this code for ages ^^
RewriteRule ^([^/.]+)(/([^/.]+))?(/([^/.]+))?$ index2.php?link=$1&sublink=$3&subsublink=$5 [L,QSA]
Note that localhost/mySite/OFFERS/ARTICLE links to localhost/mySite/?link=OFFERS&sublink=ARTICLE&sussublink= and not localhost/mySite/?link=OFFERS&sublink=ARTICLE.
Should not be a big issue, but make sure the PHP code doesn't us isset($_GET['subsublink']).
Try adding the following to your htaccess file in the mysitedirectory of your site.
RewriteEngine on
RewriteBase /mysite/
# rewrite http://localhost/mySite/OFFERS/ARTICLE/DETAIL to
# http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
#assumes that index2.php is in the root directory of site
RewriteRule ^([-a-zA-Z0-9])+/([-a-zA-Z0-9])+/([-a-zA-Z0-9])+ index2.php?link=$1&sublink=$2&subsublink=$3 [NC,L]
#redirect index to index2
#if you do not want to redirect, just server rewrite, remove the R=301 below
RewriteRule ^index\.php$ index2.php [NC,L,R=301]

Resources