htaccess Rewrite with subdir subdir - .htaccess

how to i apply a subdir to the htacces containing the following.
I tried RewriteCond %{REQUEST_URI} !^/foo/ however then I get an error, without it i am redirected to the main site.
script htaccess
IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php // I tried !^/subdir/index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
wp htaccess
# BEGIN WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP_USER_AGENT} !^.*(AdsBot-Google|Android|BB10|BlackBerry\ 9350|BlackBerry\ 9360|BlackBerry\ 9370|BlackBerry\ 9380|BlackBerry\ 9780|BlackBerry\ 9790|BlackBerry\ 9800|BlackBerry\ 9810|BlackBerry\ 9850|BlackBerry\ 9860|BlackBerry\ 9900|BlackBerry\ 9930|BlackBerry9500|BlackBerry9520|BlackBerry9530|BlackBerry9550|CUPCAKE|Googlebot-Mobile|bada|dream|froyo|iPhone|iPod|incognito|s8000|webOS|webmate).* [NC]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{HTTPS} on
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz" [L]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP_USER_AGENT} !^.*(AdsBot-Google|Android|BB10|BlackBerry\ 9350|BlackBerry\ 9360|BlackBerry\ 9370|BlackBerry\ 9380|BlackBerry\ 9780|BlackBerry\ 9790|BlackBerry\ 9800|BlackBerry\ 9810|BlackBerry\ 9850|BlackBerry\ 9860|BlackBerry\ 9900|BlackBerry\ 9930|BlackBerry9500|BlackBerry9520|BlackBerry9530|BlackBerry9550|CUPCAKE|Googlebot-Mobile|bada|dream|froyo|iPhone|iPod|incognito|s8000|webOS|webmate).* [NC]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{HTTPS} !on
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html.gz -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html.gz" [L]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP_USER_AGENT} !^.*(AdsBot-Google|Android|BB10|BlackBerry\ 9350|BlackBerry\ 9360|BlackBerry\ 9370|BlackBerry\ 9380|BlackBerry\ 9780|BlackBerry\ 9790|BlackBerry\ 9800|BlackBerry\ 9810|BlackBerry\ 9850|BlackBerry\ 9860|BlackBerry\ 9900|BlackBerry\ 9930|BlackBerry9500|BlackBerry9520|BlackBerry9530|BlackBerry9550|CUPCAKE|Googlebot-Mobile|bada|dream|froyo|iPhone|iPod|incognito|s8000|webOS|webmate).* [NC]
RewriteCond %{HTTPS} on
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html" [L]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP_USER_AGENT} !^.*(AdsBot-Google|Android|BB10|BlackBerry\ 9350|BlackBerry\ 9360|BlackBerry\ 9370|BlackBerry\ 9380|BlackBerry\ 9780|BlackBerry\ 9790|BlackBerry\ 9800|BlackBerry\ 9810|BlackBerry\ 9850|BlackBerry\ 9860|BlackBerry\ 9900|BlackBerry\ 9930|BlackBerry9500|BlackBerry9520|BlackBerry9530|BlackBerry9550|CUPCAKE|Googlebot-Mobile|bada|dream|froyo|iPhone|iPod|incognito|s8000|webOS|webmate).* [NC]
RewriteCond %{HTTPS} !on
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html" [L]
</IfModule>
# END WPSuperCache
# BEGIN WordPress
# WPhtc: Begin Custom htaccess
Action application/x-hg-php53 /cgi-sys/php53
AddType application/x-httpd-php53 .php
# WPhtc: End Custom htaccess
# WPhtC: Limit upload size to 10 MB
LimitRequestBody 10485760
# WPhtC: Protect WP-config.php
<files wp-config.php>
order allow,deny
deny from all
</files>
# WPhtC: Protect .htaccess file
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
</files>
# WPhtC: Protect comments.php
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*http://www.mysite.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
# WPhtC: Disable image hotlinking
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mysite.com/.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://www.mysite.com/hotlink.png [NC,R,L]
</IfModule>
# WPhtC: Disable file hotlinking
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mysite.com/.*$ [NC]
RewriteRule \.(mp3|mp4|m4a|pdf|zip|rar|doc|docx)$ http://www.mysite.com [NC,R,L]
</IfModule>
<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

To exclude a subdir or file for a rule, you can use ! in front of the RewriteRule pattern
RewriteRule !^subdir index.php?rewrite=2 [L,QSA]
or
RewriteRule !^subdir/index\.php$ index.php?rewrite=2 [L,QSA]

Related

htaccess chain redirect for http protocol only. How to fix?

I need to redirect all pages to the new domain. From domain.biz to domain2.org.
The htaccess redirection works, but when there's an issue of redirecting http://domain.biz, it redirects the following way
http://domain.biz -> http://www.domain.biz -> https://domain2.org
How to avoid that double redirect and make it http://domain.biz -> https://domain2.org ?
Here's my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.biz$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.biz$
RewriteRule (.*)$ https://domain2.org/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{SERVER_PORT} =443
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{HTTP:X-Forwarded-Proto} =https [NC]
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=W3TC_ENC:_gzip]
RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
RewriteRule .* - [E=W3TC_PREVIEW:_preview]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.xml%{ENV:W3TC_ENC}" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.xml%{ENV:W3TC_ENC}" [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Remove file name from url in 2nd case not work

I want to remove a file name from url, where url is: mysite.com/project.php?page=AAA and here want to remove project.php?page=. So previously I removed successfully another file name from url by below method where url was: mysite.com/userinfo.php?user=111 and removed userinfo.php?user=
htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ userinfo.php?user=$1 [L,QSA]
But now when I am going apply same method for remove project.php?page=. Its not work.
I tried:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ project.php?page=$1 [L,QSA]
Here is all htaccess
#Remove php#
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
#Remove Userinfo#
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ userinfo.php?user=$1 [L,QSA]
To redirect from mysite.com/userinfo.php?user=111 to mysite.com/111 it is enough 2 lines:
RewriteCond %{QUERY_STRING} user=([^?&]+) [NC]
RewriteRule ^userinfo.php$ /%1? [R,L]

Add trailing slash to url only works with non-ww redirect

I'm trying to add a trailing slash to the url. It nearly works but there is a little problem i don't understand.
When i call the site http://domain.com/test > rewrite to www.domain.com > the trailing slash is added.
When i call the site directly http://www.domain.com/test > nothing is added.
Important to me is that https:// has to be redirected to https:// an not to http://
Here's my config:
############################################
enable rewrites
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !.html
RewriteCond %{REQUEST_URI} !.php
RewriteCond %{QUERY_STRING} !price
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
Replace your rules with these simplified rules:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+?)/?$ http%1://www.domain.com/$1/ [R=302,L,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

Joomla .htaccess

I need a working RewriteRule to get rid of the /index.php/category/ part of my url(s).
bruteforce.tv/index.php/streams/shinigamily
bruteforce.tv/index.php/streams/cash
bruteforce.tv/index.php/streams/blacktigrex
bruteforce.tv/index.php/streams/viktorwwe
TO
bruteforce.tv/shinigamily
bruteforce.tv/cash
bruteforce.tv/blacktigrex
bruteforce.tv/viktorwwe
I'm not used to it with working with a htaccess file so I apologize for being completely unresourceful.
This is my current htaccess file with the not working RewriteRule ^streams/(.*)/?$ /$1 [L,NC,R]
Options +FollowSymLinks
## Mod_rewrite in use.
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteBase /
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^streams/(.*)/?$ /$1 [L,NC,R]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Use Joomla's built-in feature to remove /index.php (under global config > site)
RewriteRule ^streams/(.*)$ http://bruteforce.tv/$1 [R=301,L]

.htaccess domain forwarding issue

The following code in the .htaccess file is supposed to, among others I guess, redirect the secondary domains towards the main domain:
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^secondaryDomain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain1.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain2.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain3.com$ [OR]
RewriteCond %{HTTP_HOST} ^secondaryDomain3.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain4.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain4.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain5.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain5.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain6.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain6.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain7.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain7.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
Unfortunately if I type www.secondaryDomain.com/index.html or www.secondaryDomain.com/directory it is not redirected towards the main domain.
What has been done wrong in the .htacess file?
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
This rewrites only URLs ending in / or nothing at all. You should use something like:
RewriteRule (.*) "http\:\/\/mainDomain\.com$1" [R=301,L,QSA]
Which redirects and preserves all path-info.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ http://mainDomain.com/ [L]
</IfModule>
I am assuming that this .htaccess file is for secondarydomain.com ...

Resources