Htaccess issue with subfolder and with languange - .htaccess

I have a core PHP website that is hosted over a server and now I have moved the website to a subfolder to access the website something like that example.com/site. that website also use the .htaccess for managing multiple language.but after moving it to subfolder website is not accessible. Please see the following .htaccess file. This .htaccess is when the website is on root folder I want this .htacess to work when on subfolder /site/ please help me.
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) https://www.example.com/$1 [L,R=301]
<IfModule mod_rewrite.c>
# URL rewriting module activation
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^en/([^?&]*)$ /$1?lang=en [QSA,L]
RewriteRule ^en/privacy-policy$ /privacy-policy.php?lang=en [QSA,L]
RewriteRule ^en/legal-notice$ /legal-notice.php?lang=fr [QSA,L]
RewriteRule ^fr/politique-de-confidentialite$ /privacy-policy.php?lang=fr [QSA,L]
RewriteRule ^fr/mentions-legales$ /legal-notice.php?lang=fr [QSA,L]
RewriteRule ^fr/([^?&]*)$ /$1?lang=fr [QSA,L]
</IfModule>

You may try these rules in /site/.htaccess:
RewriteEngine On
# add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^en/privacy-policy/?$ privacy-policy.php?lang=en [QSA,L]
RewriteRule ^en/legal-notice/?$ legal-notice.php?lang=fr [QSA,L]
RewriteRule ^fr/politique-de-confidentialite/?$ privacy-policy.php?lang=fr [QSA,L]
RewriteRule ^fr/mentions-legales/?$ legal-notice.php?lang=fr [QSA,L]
RewriteRule ^(en|fr)/(.*)$ $2?lang=$1 [QSA,L]

You can add
RewriteBase /site/
then write the conditions like
RewriteRule ^site/en/privacy-policy/?$ site/privacy-policy.php?lang=en [QSA,L]

Related

Root htaccess overriding the sub folder htaccess

I have a htaccess file in root and another htaccess in films folder. I want to stop all the rewrite urls or conditions to affect the films folder. I have some other rules in film folder htaccess.
My root htaccess looks like this
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^abc\.in$ [NC]
RewriteRule ^(.*)$ http://www.abc.in/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
My sub directory films folder htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /films/
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^change-password/$ changepassword.php
RewriteRule ^change-password$ changepassword.php
The above code is just a glimpse of my original htaccess
You can do it by following code :-
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/films/$1 [R=301,L]
It may help you.
In /films/.htaccess ,Change your rule
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
to this :
RewriteRule ^(.*)$ http://%1/films/$1 [R=301,L]
To redirect all /films requests to www, you can use something like the following :
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

Redirecting to homepage htaccess issue

I have a strange issue where pages are redirecting to the homepage. Let me explain - my website is thedj.com.au
Now when I type in www.thedj.com.au/payments it redirects to thedj.com.au (even though it should be going to the page https://thedj.com.au/payments).
Any idea why this is and how to fix?
My htaccess file is below:
# BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^home.htm$ https://thedj.com.au/ [R=301,L]
RewriteRule ^photos.htm$ http://photos.thedj.com.au/ [R=301,L]
RewriteRule ^contacts.htm$ https://thedj.com.au/contact-us/ [R=301,L]
RewriteRule ^booking.htm$ https://thedj.com.au/book-dj/ [R=301,L]
RewriteRule ^downloads.htm$ https://thedj.com.au/downloads/ [R=301,L]
RewriteRule ^payonline.htm$ https://thedj.com.au/payments/ [R=301,L]
RewriteRule ^price.htm$ https://thedj.com.au/pricing/ [R=301,L]
RewriteRule ^questions.htm$ https://thedj.com.au/faq/ [R=301,L]
RewriteRule ^links.htm$ https://thedj.com.au/links/ [R=301,L]
RewriteRule ^thankyous/index.htm$ https://thedj.com.au/testimonials/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://thedj.com.au/ [L,R=301]
</IfModule>
# END HTTPS Redirection Plugin
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^mrdj\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mrdj\.net\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mrdj\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mrdj\.com\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^thedjs\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.thedjs\.com\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^theperthweddingdjs\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.theperthweddingdjs\.com$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^thedjs\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.thedjs\.net\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au" [R=301,L]
Note:
I've tried commenting out the lines
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://thedj.com.au/ [L,R=301]
However this has not fixed the issue. I'm thinking this may perhaps be because the website is entirely https:// - but any more ideas would be much appreciated.
Best,
Kosta
The .htaccess shouldn't do any redirect here.
For testing, this website could be useful.
Is this configuration from your live site? Because https://thedj.com.au/payments works for me.
Browsers tend to cache permanent redirects quite aggressively. You need to clear the complete cache or use the private browsing mode to test a redirect again. (But you need to close ALL private browsing windows and then open a new one)

how to ignore the .htaccess file from a parent directory

I'm using rewrite rules for search engine optimized url's
In my root folder I have the following .htaccess file:
Options +FollowSymlinks RewriteEngine On RewriteCond %{http_host} ^elitegameservers.net [NC]
RewriteRule ^(.*)$ http://www.elitegameservers.net/$1 [R=301,L]
rewriteEngine on
rewriteBase /
rewriteCond %{HTTP_HOST} ^(.*)haloservers(.nl|.us|.net)$
rewriteRule ^(.*) http://www.haloservers.net/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?haloservers(.nl|.us|.net) [NC]
RewriteRule ^(.*)\.html$ http://www.elitegameservers.net/$1 [R=301,L]
In the sub directory(/controlpanel) I run WHMCS with the following .htaccess file:
RewriteEngine On
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^elitegameservers.net [NC]
RewriteRule ^(.*)$ http://www.elitegameservers.net/controlpanel/$1 [R=301,L]
RewriteEngine On
# Announcements
RewriteRule ^announcements/([0-9]+)/[a-z0-9_-]+\.html$ ./announcements.php?id=$1 [L,NC]
RewriteRule ^announcements$ ./announcements.php [L,NC]
# Downloads
RewriteRule ^downloads/([0-9]+)/([^/]*)$ ./downloads.php?action=displaycat&catid=$1 [L,NC]
RewriteRule ^downloads$ ./downloads.php [L,NC]
# Knowledgebase
RewriteRule ^knowledgebase/([0-9]+)/[a-z0-9_-]+\.html$ ./knowledgebase.php?action=displayarticle&id=$1 [L,NC]
RewriteRule ^knowledgebase/([0-9]+)/([^/]*)$ ./knowledgebase.php?action=displaycat&catid=$1 [L,NC]
RewriteRule ^knowledgebase$ ./knowledgebase.php [L,NC]
I noticed that knowledgeable SEO optimization in WHMCS doesn't seem to work properly and it seems to be caused by the .htaccess code in my root directory.
Because of that I want the controlpanel sub directory to be excluded from the code in the root directory.
Thanks for any help
You could try adding a condition to the rules in your root directory to exclude requests starting with controlpanel:
RewriteCond %{REQUEST_URI} !^/controlpanel
rewriteCond %{HTTP_HOST} ^(.*)haloservers(.nl|.us|.net)$
rewriteRule ^(.*) http://www.haloservers.net/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/controlpanel
RewriteCond %{HTTP_HOST} ^(www\.)?haloservers(.nl|.us|.net) [NC]
RewriteRule ^(.*)\.html$ http://www.elitegameservers.net/$1 [R=301,L]

.htaccess redirection not working

I try to redirect http://mydomain.com to http://www.mydomain.com
I add this to my htaccess file, but it not work :
RewriteCond %{HTTP_HOST} ^mydomain\.fr [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [L,R=301]
This is the complete file :
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.fr [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [L,R=301]
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Try:
RewriteCond %{HTTP_HOST} !^www.mydomain.fr [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [L,R=301]
I'm using this on an existing site at the moment - seems to work fine here.
# Never keep domain name without subdomain
RewriteCond %{HTTP_HOST} ^mydomain\.fr$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.fr/$1 [R=301,L]

How to fix URL canonicalization with .htaccess?

I wan't the server to always redirect my URL's to format as "http://www.domain.com", even if the user write just "domain.com".
I could find some examples of this on the web, but I already have some fixes in .htaccess file and I don't know, where to put what, so it does't clash with the previous code.
Here's my .htaccess file:
RewriteEngine on
RewriteBase /
ErrorDocument 404 /404
RewriteRule ^adminator/?$ adminator/login.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3&detail4=$4 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/?$ index.php?detail1=$1 [QSA,L]
What should I put in, so it does the URL redirect to "www"?
And one last question, is it all I have to do, so search engines don't have problems with the URL's?
I usually do the contrary.
you probably want www.example.com to forward to example.com -- shorter URLs
are sexier.
no-www.org/faq.php?q=class_b
Thanks to HTML5 boilerplate, I usually add :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
If you want to do that in your .htaccess :
RewriteEngine on
RewriteBase /
ErrorDocument 404 /404
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^adminator/?$ adminator/login.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3&detail4=$4 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/?$ index.php?detail1=$1 [QSA,L]
Else, try the inverse RewriteCond and associate RewriteRule
Your [^/\\.] pattern simplifies to [^/.] as the period does NOT need escaping.

Resources