So, I am having some issues with my htacces file trying to do some re-write conditions.
What I am trying to do is:
There are multiple domains pointed to this web folder.
If the domain is anything but example.com I want it to rewrite to example.com
UNLESS - the path is /path
Everything is working now except when you go to www.otherexample.com/path
It is hitting the last rule and changing the url to http://dev.otherexample.com/index.php?qs-rewrite=path and causes a redirect loop.
Here's the entire htaccess file
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} !example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/path [NC]
RewriteRule ^.*$ http://dev.example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qs-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
This should be your complete .htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/path [NC]
RewriteCond %{QUERY_STRING} !qs-rewrite=[^&]+ [NC]
RewriteRule ^ http://dev.example.com%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . /%1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php?qs-rewrite=%{REQUEST_URI} [L,QSA]
</IfModule>
Related
I have an htaccess file that
Takes care of making for example example.com/fr behave as example.com/index.php?lang=fr
Handles the blog:
--
RewriteEngine On
RewriteCond %{ENV:REDIRECT_rewritten} !=1
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})$ [NC]
RewriteRule ^([^/]*)$ /%1/$1? [R=301,L]
RewriteCond %{REQUEST_URI} !^/js/
RewriteRule ^([a-z]{2})(?:/([^/]+))?$ $2?lang=$1 [NC,L,QSA,E=rewritten:1]
#If the following part is removed, it works fine
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
How to fix this?
RewriteBase isn't even needed here because that is applicable for relative paths in .htaccess.
You should keep these rules in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+[^?]*\?lang=([^\s&]+)\s [NC]
RewriteRule ^ /%2/%1? [R=301,L,NE]
RewriteCond %{REQUEST_URI} !^/js/
RewriteRule ^([a-z]{2})(?:/([^/]+))?$ $2?lang=$1 [NC,L,QSA]
And create blog/.htaccess and keep these rules in blog/.htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
I have searched how to redirect url with parameters to root dir but I can't get it to work :(
This is what the .htaccess code looks like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^phpnuke/modules\.php$ /? [L,R=301]
I have url such as "http://www.domain.com/phpnuke/modules.php?name=News&file=article&sid=60" and I want to redirect it to "http://www.diagonally.org/"
Try some thing like this
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R]
Keep redirect rule before default WP rewrite rule and match correct query string:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} name=News&file=article&sid=60
RewriteRule ^phpnuke/modules\.php$ /? [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I transfered an old bulletin board to q2a.org. Now i have a lot index.php files in google which do as 200 OK Status. How can I redirect those links to root? ex. www.domain.com/index.php?page=Board&boardID=14 or www.domain.com/index.php?page=Thread&postID=58585
This is my current .htaccess file
ErrorDocument 404 /404.php
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
Thanks
Insert this rule just after RewriteBase line:
RewriteCond %{QUERY_STRING} page=[^&]+&postID=[^&]+ [NC]
RewriteRule ^ /? [R=301,L]
I have a problem with duplicate contents in search engine .
I can access a page in q2a web site using both of these url's !
http://www.domain.com/index.php?qa=1306&qa_1=title
http://www.domain.com/1306/title
I want to redirect the first one to second 1 how ca I do it ?
I tried codes in these page and other things too but none of them works :(
htaccess for changing index.php?ms=user to /user
my current htaccess is :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Redirect 301 /math/ http://math.domain.com/
</IfModule>
I used these and It seems work fine :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^users/?$ /index.php?qa=users [R=301,L]
RewriteRule ^tags/?$ /index.php?qa=tags [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/qa-theme/.*
RewriteCond %{REQUEST_URI} !^/qa-content/.*
RewriteCond %{REQUEST_URI} !^/analytic/.*
RewriteCond %{REQUEST_URI} !^/qa-plugin/.*
RewriteCond %{REQUEST_URI} !^/help_files/.*
RewriteRule ^(.*)/(.*)/?$ /index.php?qa=$1&qa_1=$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/qa-theme/.*
RewriteCond %{REQUEST_URI} !^/qa-content/.*
RewriteCond %{REQUEST_URI} !^/analytic/.*
RewriteCond %{REQUEST_URI} !^/qa-plugin/.*
RewriteCond %{REQUEST_URI} !^/help_files/.*
RewriteRule ^(.*)/(.*)/(.*)/?$ /index.php?qa=$1&qa_1=$2&qa_2=$3 [R=301,L]
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Redirect 301 /math/ http://math.domain.com/
</IfModule>
I have CodeIgniter setup in a sub-directory of a sub-domain. My htaccess file works for the following: http://subdomain.domain.com/subdirectory/
The working htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /subdirectory/
RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php?/$1 [L]
However this does not work when I point a domain name http://www.mydomainname.org to public_html/subdirectory.
What I'm attempting to achieve is I'd like to use http://www.mydomainname.org/whatever/ to mask http://sub.domain.com/subdirectory/index.php/whatever
Is this possible? Is there anything I can add to my htaccess that will allow me to achieve this?
I attempted to use the htaccess answer here, but had no luck.
I think if you want both to work, you'll need to add extra conditions for the hostname, try something like:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# for main domain
RewriteCond %{HTTP_HOST} ^(www\.)?mydomainname\.com$ [NC]
RewriteRule ^$ /index.php [L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomainname\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php?/$1 [L]
# for subdomain
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^$ /subdirectory/index.php [L]
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(?:subdirectory/|)(.*)$ /subdirectory/index.php?/$1 [L]