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]
Related
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]
i want to redirect
http://subdomain.example.com/index.php?pageID=45
to
http://example.com/subdomain/45.html
Please help me with this
i tried
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.example.com/sudomain/$1 [L,R=301]
You can replace your code by this one in your htaccess (in root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^pageID=([1-9][0-9]*)$ [NC]
RewriteRule ^index\.php$ http://example.com/subdomain/%1.html? [R=301,L]
Hi i need to use this existing htaccess located on the root folder.
I now need to create a new directory /testfolder/ to become http://www.companydomain.com/testfolder/ where all the files of the root will be located.
How can I make this happen with this existing htaccess? Much appreciated your help in advance!
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_URI} !(.*)/(.*).html$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
# 301
RewriteCond %{HTTP_HOST} !^www\.companydomain\.com$ [NC]
RewriteRule .? http://www.companydomain.com%{REQUEST_URI} [R=301,L]
RewriteRule ^Sportsbooks\/(.*).html$ Sportsbooks\/$1\/ [R=301,L]
This .htaccess file will redirect http://example.com/file.html to http://example.com/folder1/file.html:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteCond %{HTTP_HOST} !folder1
RewriteRule ^(.*)$ http://example.com/folder1/$1 [R=301,L]
I hope this helps!
I have an issue that's too complex for me to handle, but I'm betting someone has had to do this before, so please let me hear from you. ;)
Here's the situation:
I've got 1 main domain with 3 subdirectories that are nested within each other
(from top to bottom)
http://main-domain.com
then
http://main-domain.com/company-name/
then
http://main-domain.com/company-name/blog/
There's currently 3 .htaccess files -- 1 in each of the 3 directories shown above.
What's the problem?
Instead of having www.main-domain.com/company-name/blog/whatever, I'd like to have main-domain.com/blog/whatever
So, I want to drop the www AND more importantly, drop the middle subdirectory; i.e. /company-name/
I hope that the following examples will help to illustrate the point.
http://main-domain.com/company-name/index.php should be changed to http://main-domain.com/index.php
http://main-domain.com/company-name/blog/my-first-article/ should be changed to http://main-domain.com/blog/my-first-article/
Why do I need this?
I need a shorter URL that is more SEO-friendly. I have too many backlinks that use the 'old' urls, so I need to mod-rewrite them all.
Here are My Current 3 htaccess files
root htaccess: main-domain.com
#Bypass InoCore Templating System
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /reservations/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /reservations/default.php [L]
Options -Indexes
</IfModule>
#END Bypass
#301 REDIRECT
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^info.php - [L]
RewriteCond %{HTTP_HOST} ^www.domain1.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^domain1.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^www.domain2.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^domain2.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^www.domain3.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^domain3.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^main-domain.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^www.main-domain.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com/company-name/$1 [R=301,NC]
company-name htaccess: main-domain.com/company-name/
RewriteEngine on
RewriteRule ^maping.php /maping.php
RewriteRule ^$ index.php?$1 [L]
RewriteRule (.*) index.php?$1 [L]
#php_flag magic_quotes_gpc off
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /company-name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /company-name/index.php [L]
</IfModule>
#END WordPress
blog htaccess: main-domain.com/company-name/blog/
RewriteEngine off
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /company-name/blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /company-name/blog/index.php [L]
</IfModule>
#END WordPress
Your correct and compact root .htaccess should be like this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^info.php - [L]
# match all the domains in single condition while www. is optional
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1|domain2|domain3|main-domain)\.(com|tld)$ [NC]
RewriteRule ^company-name/(.*)$ http://www.domain.tld/$1 [R=301,L,NC,NE]
R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
NC is for ignore case comparison
$1 is your REQUEST_URI matching group
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]