rewrite condition in .htaccess - .htaccess

I am trying to make partners readable on the website i.e. http://domain.com/partners. but the pinnaclecart doesn't allow it to be readable or accessable on the browser. i created the directory partners so i could write the whole different files from the pinnaclecart.
inside .htaccess: you can see "partners" at the end.
EDIT II
RewriteEngine ON
RewriteRule ^homepage.html$ index.php
RewriteRule ^home.html$ index.php
<IfModule mod_headers.c>
Header unset ETag
FileETag None
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified
Header set Expires "Fri, 21 Dec 2020 00:00:00 GMT"
Header set Cache-Control "public, no-transform"
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^((.)?)$ index.php?p=home [L]
RewriteCond $1 /var/www
RewriteRule ^(.+)$ / [L]
RewriteCond $1 !^(\#(.)*|\?(.)*|admin\.php(.)*|ses\/(.)*|ecc\/(.)*|index\.php(.)*|login\.php(.)*|\.htaccess(.)*|images\/(.)*|\.htaccess\.back(.)*|3cc4da-pinnacle_zend_3\.7\.7_sdk\.zip(.)*|dump\.sql(.)*|content\/(.)*|download\.php(.)*|readme\.txt(.)*|in_case_of_install\/(.)*|robots\.txt(.)*|images\.zip(.)*|partners\/(.)*)
RewriteRule ^(.+)$ index.php?url=$1&%{QUERY_STRING} [L]
</IfModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|ico|flv|jpg|jpeg|png|gif)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
Why is it not accessable on the browser?
EDIT
is there no answer to this for solutions?

As people mentioned you may wish to post more of your .htaccess file to help debugging, but I couldn't help but notice that the last part of your regex reads:
partners\/(.)
This seems odd as it will only match single letter items in that directory. So I am not 100% sure its your problem but I suspect you intended that to read:
partners\/(.)*

Related

Htaccess order of mod modules

I'm writing a script that will alter the roots .htaccess file to block user agents (yandex in this example). I wrote it to use the setenvif command but it wasn't working. Via another post here I was told it was because a redirect prior to the command was causing it to fail due to the .htaccess file being reloaded. I added a rewritecond statement to do the block and it worked. If I place the setenvif statement at the top of the file it also works correctly.
In researching this others have stated that mod_rewrite is handled before mod_alias but I can't find any mention of when mod_setenvif is handled. There also seems to be little information regarding the order of things in the .htaccess file in general. Below is an example of the things in my .htaccess file. Even as a novice I can see it is not ordered well.
But before I deal with that I wanted to see where to properly place the setenvif statement?
And am I correct in assuming that any setenvif, rewritecond and deny statement that causes a block or redirect to another site should be placed at the top?
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "WOW32" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "WOW64" [NC]
RewriteRule ^(.*)$ - [F]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
redirect 301 /about_us.php https://example.com/about.html
<Files test.html>
order allow,deny
</Files>
<FilesMatch "\.(inc|tpl|h|ihtml|sql|ini|conf|class|bin|spd|theme|module|exe)$">
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
ErrorDocument 400 /server_error.php?id=400
order allow,deny
deny from 1.2.3.4/32
allow from all
SetEnvIfNoCase User-Agent "^yandex$" my_block
<IfModule !authz_core_module>
Order Allow,Deny
Allow from ALL
Deny from env=my_block
</IfModule>
RewriteCond %{HTTP_USER_AGENT} ^.*(yandex).*$ [NC,OR]

Replace blog with static page redirect rest to /blog with htaaccess

I have a website that currently has a WordPress blog. I want to move the blog into /blog and make the static page the new "root".
That's easy in terms of FTP, just moving folders along.
However, I'd love to get anything that would normally be 404 to get redirected to the /blog part so content doesn't get lost on the migration.
Is this doable with .hatccess?
Current .htaccess file:
#DirectoryIndex index.php index.html
#Options +FollowSymLinks
# Indexes
Options All -Indexes
# REDIRECT https
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
# BEGIN WordPress
# Dynamically generated by WP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN FileETag MTime Size
<ifmodule mod_expires.c>
<filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresActive on
ExpiresDefault "access plus 1 year"
</filesmatch>
</ifmodule>
# END FileETag MTime Size<!--formatted-->
# Protecting htaccess
<files .htaccess>
order allow,deny
deny from all
</files>
# Protecting wpconfig.php
<files wp-config.php>
order allow,deny
deny from all
</files>%
Assuming the "current .htaccess file" you have posted is the .htaccess file you intend to move to /blog/.htaccess. In which case you will need to change it as follows:
#DirectoryIndex index.php index.html
#Options +FollowSymLinks
# Indexes
Options All -Indexes
# REDIRECT https
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
# Dynamically generated by WP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
# BEGIN FileETag MTime Size
<ifmodule mod_expires.c>
<filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresActive on
ExpiresDefault "access plus 1 year"
</filesmatch>
</ifmodule>
# END FileETag MTime Size<!--formatted-->
# Protecting htaccess
<files .htaccess>
order allow,deny
deny from all
</files>
# Protecting wpconfig.php
<files wp-config.php>
order allow,deny
deny from all
</files>
Notable changes:
Changed HTTP to HTTPS redirect to use the REQUEST_URI server variable instead of a backreference. With it being in a subdirectory (blog), the subdirectory would otherwise be omited from the redirect to HTTPS.
Commented out (removed) the RewriteBase directive. This is not required here, but if you did need to set this, it should be set to RewriteBase /blog.
Removed the slash prefix on the RewriteRule substitution string. ie. Changed this RewriteRule . /index.php [L] to this RewriteRule . index.php [L]
Without the RewriteBase defined, this is now relative to the current directory, ie. /blog. Without having to explicitly state the /blog directory.
You had an erroneous % at the end of the file?
I'd love to get anything that would normally be 404 to get redirected to the /blog part so content doesn't get lost on the migration.
This can perhaps be refined if we know the format of your original URLs, however, we basically need to redirect any request for anywhere outside of the /blog subdirectory - that would trigger a 404 - to be redirected to the /blog subdirectory.
You need to create a new .htaccess file in the document root with the following:
RewriteEngine On
# Redirect any 404s back to the "/blog" directory
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule !^blog/ /blog%{REQUEST_URI} [R=301,L]
The above would redirect a request for /foo to /blog/foo. But a request for /blog/bar would not be touched by this directive and routed through WordPress as normal (probably resulting in a 404 generated by WordPress).
You should first test with a 302 (temporary) redirect to avoid potential caching issues and only change to a 301 (permanent) redirect once you have confirmed it works as intended.
Try using the ErrorDocument directive
ErrorDocument 404 /blog

How do I correctly handle multiple capturing groups in .htaccess?

I'm trying to get:
example.com/curriculum/<curriculum name>/unit/<unit name>/
to rewrite to:
example.com/curriculum/unit/?c=<curriculum name>&u=<unit name>
so far I have:
RewriteRule ^/curriculum/([A-Za-z0-9_-]+)/unit/([A-Za-z0-9_-]+)/?$ https://www.example.com/curriculum/unit/?c=$1&u=$2
Considering that:
RewriteRule ^curriculum/([A-Za-z0-9_-]+)/?$ https://www.example.com/curriculum/?c=$1
works as expected, I assume my syntax is off, as when loading, I just get error 404, with the URL not rewritten from its original format. To clarify, /curriculum/unit does exist.
Any guidance or advice on what I need to do to make this work? Thanks!
Update
Full .htaccess file as requested:
### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
ExpiresByType image/gif A2592000
### Expire everything else 1 day from when it's last modified
### (this uses the Alternative syntax)
ExpiresDefault "modification plus 1 day"
### Apply a Cache-Control header to index.html and styles.css
###Cross-Site Scripting protection
Header always set X-Xss-Protection "1; mode=block"
###Disallow websites to frame legacycars - user protection
Header always append X-Frame-Options SAMEORIGIN
<IfModule mod_headers.c>
#No Cache browser revalidates on each request and fetches new version IF contents change based on ETag or Last-Modified response
<FilesMatch "\.(html|php)$">
Header set Cache-Control "no-cache"
</FilesMatch>
#DAY Stock and Cover images expire at the end of each day, but must be checked for changes
<FilesMatch "\.(jpg|jpeg)$">
Header set Cache-Control "max-age=86400, public, must-revalidate"
</FilesMatch>
#WEEK Icons and badges expire after a week
<FilesMatch "\.(ico|png|gif|swf|svg|xml)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
#MONTH Site framework expires after a month, but must be checked for changes
<FilesMatch "\.(js|css|json)$">
Header set Cache-Control "max-age=2628000, public, must-revalidate"
</FilesMatch>
#Hide .credentials
<FilesMatch ".credentials.php">
Order allow,deny
Deny from all
</FilesMatch>
Options +FollowSymLinks -MultiViews
ErrorDocument 404 https://www.example.com/error/404.html
ErrorDocument 403 https:/www.example.com/error/403.html
# Turn mod_rewrite on
RewriteEngine On
#Rewrite curriculum and unit to GET vars
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^curriculum/([\w-]+)/unit/([\w-]+)/?$ curriculum/unit/?c=$1&u=$2 [L,QSA,NC]
RewriteRule ^curriculum/([\w-]+)/?$ curriculum/?c=$1 [L,QSA,NC]
# Externally redirect direct client requests for subdomain-subdirectory URLs
# to subdomain URLs without subdomain-subdirectory URL-path
Redirect permanent /sd_manage/ https://manage.example.com
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^manage(.*)$ https://manage.example.com [R=301,L]
RewriteRule ^manage/(.*)$ https://manage.example.com/$1 [R=301,L]
# Rewrite root subdomain to www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
# Rewrite valid subdomains to the secure site
RewriteCond %{HTTPS} off
# RewriteCond %{HTTP_HOST} ^(www|manage)\.example\.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
You may keep these 2 rewrite rules:
ErrorDocument 404 /error/404.html
ErrorDocument 403 /error/403.html
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Externally redirect direct client requests for subdomain-subdirectory URLs
# to subdomain URLs without subdomain-subdirectory URL-path
RewriteRule ^sd_manage/ https://manage.example.com [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^manage(/.*)?$ https://manage.example.com$1 [R=301,L,NC,NE]
# Rewrite root subdomain to www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Rewrite valid subdomains to the secure site
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
#Rewrite curriculum and unit to GET vars
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^curriculum/([\w-]+)/?$ curriculum/?c=$1 [L,QSA,NC]
RewriteRule ^curriculum/([\w-]+)/unit/([\w-]+)/?$ curriculum/unit/?c=$1&u=$2 [L,QSA,NC]

URL Canonicalization through .htaccess

I'm trying to redirect http://www.example.me to http://example.me, but for some reason it's not working. Can somebody help me with this by telling what is wrong on my .htaccess file?
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
RewriteRule ^(.*)$ – [F,L]
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/“ [R=301,L]
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
Try this and also do not use quotes in your rule
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^ http:\\example.me [R=301,L]
It was a problem with the quotes. Below is the correct .htaccess
The error was on this line with the last quote
RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]
Below you can check the full correct .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
RewriteRule ^(.*)$ – [F,L]
RewriteCond %{HTTP_HOST} ^www\.example\.me$
RewriteRule ^/?$ "http\:\/\/example\.me\/" [R=301,L]
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 month
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A2419200
Header append Cache-Control "public"
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive On
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>

.htaccess https breaks rewrite rules

I am experienceing some .htaccess redirect issues.
Mainly I do not care if the user is on https unless I send them there, I have found alot of resources on how to force https, but that is not what I am trying to do.
this is a example of my htaccess:
Options -Indexes
Options -MultiViews
<filesMatch "\.(html|htm|txt|js|htaccess)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
ErrorDocument 404 /404.php
RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Main site rules
RewriteRule ^about/?$ about.php [NC,L]
I am able to force https using:
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But then the example rule which redirects to about.php does not work.
How do I allow for https in my redirects?
I also experimented with:
Define servername www.example.com
Define SSL
But I did not understand its function or implementation.

Resources