.htaccess complex and very tricky redirection - .htaccess

Here is my current .htaccess and remember I need some .htaccess that can destroy my current .htaccess.
Current .htaccess:
RewriteRule ^join$ https://example.com/internalpath/join/index.php [L,QSA]
RewriteRule ^join/(.*)$ https://example.com/internalpath/join/$1 [L,QSA]
Now my problem:
I want to redirect each and every file and directories to HTTP, except these two:
https://example.com/join/
https://example.com/join
Remember, I want every link on http except this above provided link, other then all files and directories and even files and directories in /join/ or /join will be HTTP, just two links on HTTP, but please it will not destroy the previous written .htaccess.

Above thr rules that you have add this:
RewriteCond %{HTTPS} on
RewriteRule !^join/?$ http://domain.com%{REQUEST_URI} [L,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!

301 redirect a whole directory to a specific thread/link (same domain)

I would like to add a 301 redirect to a whole directory and redirect every single link of this directory to a specific thread/post on the same domain.
I am using an apache server so i suppose i will have to edit the .htaccess
I want all the threads of this directory:
http://example.com/f73
To be redirected there:
http://example.com/f75/newthread-1990/#post333
I have read some different solutions and got confused :(
Some guys recommend to use the "Redirect" command and other recommend the "RedirectMatch" command...
I also read that the command should be different if the .htaccess is already edited and has some rewrite rules. Not sure if it makes sense or if i misunderstood, but at the moment i have added the following lines to the .htaccess:
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ htt://example.com/$1 [L,R=301]
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteRule ^f73 /f75/newthread-1990/#post333 [L,NC,NE,R=301]

.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.

How do I fix old links after modifing .htaccess for Joomla installation in a subfolder?

I have my main Joomla installation in a subdirectory. I used to redirect users from www.mysite.com to www.mysite.com/subdir with a 301 so that the live site was entirely dislocated over there.
I don't actually like the fact that all the URL are preceded by the subdirectory /subdir/ (and I also think this is not very good for SEO) so I modified my .htaccess file like this:
RewriteEngine On
RewriteBase /
# Add trailing slash if path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.mysite.com/$1/ [R=301,L]
#Change http://yoursite.com to http://www.mysite.com (Optional)
RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^/?(.*)$ http://www.mysite.com/$1 [R=301,L]
#Rewrites http://www.mysite.com/subdir to http://www.mysite.com/
RewriteRule ^(.*)$ subdir/$1 [L]
I also edited the configuration file for Joomla! so that now all the links in the site point (correctly) to www.main.com/theirquery and noto to www.main.com/subdir/theirquery
Now, however, all the old links (that have been posted to other webistes, for example) appears to be broken (404): how can I solve this?
I think I have to redirect (301) them to the new subdirectory-free address, that will be (another time) silently redirected with the htaccess I posted.
But I don't know how to do this!
Thank you in advance!
Can you try setting the $live_site parameter in configuration.php? You need to edit it directly rather than through the backend of Joomla.
You need to add this to your htaccess.
RewriteRule ^subdir/(.*)$ /$1 [R=301,NC,L]
This is not possible since the old links where not physical but stored in a database, so redirecting them wouldn't be possible without passing through the database again.

Resources