Redirect htaccess issue with pdf? - .htaccess

This is all of the .htaccess code:
DirectoryIndex index.php
<IfModule mod_php5.c>
php_value memory_limit 256M
php_value max_execution_time 18000
php_flag magic_quotes_gpc off
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
php_flag zend.ze1_compatibility_mode Off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_deflate.c>
</IfModule>
<IfModule mod_ssl.c>
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
AddDefaultCharset Off
<IfModule mod_expires.c>
ExpiresDefault "access plus 1 year"
</IfModule>
Order allow,deny
Allow from all
<Files RELEASE_NOTES.txt>
Order allow,deny
Deny from all
</Files>
Redirect 301 /content http://www.axelen.ro/tapet/
Redirect 301 /content/documents/xh76.pdf http://www.axelen.ro/
So for some reason it does not redirect PDFs. It redirects me to 404. If you try http://www.axelen.ro/content it will successfully redirects to http://www.axelen.ro/tapet/, but the PDF is not working, what should I do?

The redirect for your xh76.pdf is not working because the first generic redirect rule (/content) matches the request URL -> it's applied first.
From http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect:
Then any request beginning with URL-path will return a redirect request to the client at the location of the target URL.
Example:
Redirect /service http://foo2.example.com/service
If the client requests http://example.com/service/foo.txt, it will be told to access http://foo2.example.com/service/foo.txt instead. Only complete path segments are matched, so the above example would not match a request for http://example.com/servicefoo.txt.
The solution could be to swap the two rules so the more specific rule is being tested first or use a regular expression (eg. /content$) and the RedirectMatch directive as the documentation says.

Related

.htaccess how to redirect domain except for home page & subdirectory

From this answer on how to redirect a domain except for a subdirectory, and this answer on how to redirect a domain except for the homepage, I have ended up with the following in .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?this\.example.com$ [NC]
RewriteRule !^support !^directory-1 !^directory-2 (.+) https://www.this2.com%{REQUEST_URI} [NE,NC,R=301,L]
</IfModule>
However, this.example.com/work is not redirecting to www.this2.com/work.
Help appreciated.
Update, from anubhava's answer, this is my new .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^doig\.website\.technology$ [NC]
RewriteRule !^($|support|dynamic-keyword-module-drupal8|dynamic-keyword-plugin-joomla) https://www.webby.net.au%{REQUEST_URI} [NE,NC,R=301,L]
</IfModule>
However, https://doig.website.technology/my-work/ is not redirecting.
Update 2: this is my full .htaccess:
# Redirects
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^doig\.website\.technology$ [NC]
RewriteRule !^($|support|dynamic-keyword-module-drupal8|dynamic-keyword-plugin-joomla|wp-content|wp-includes|wp-admin) https://www.webby.net.au%{REQUEST_URI} [NE,NC,R=301,L]
</IfModule>
# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule min/\w+\.(css|js) - [E=cache-control:no-vary]
</IfModule>
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
# END LSCACHE
# BEGIN litespeed noabort
<IfModule rewrite_module>
RewriteEngine On
RewriteRule .* - [E=noabort:1]
</IfModule>
# END litespeed noabort
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteRule ^support\/?(.*)$ "https\:\/\/doig\.website\.technology\/support\/$1" [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} ^/?wp\-content/+debug\.log$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* - [F,L,NC]
</IfModule>
<IfModule !mod_rewrite.c>
<Files "debug.log">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
</IfModule>
# BEGIN Wordpress (new)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END Wordpress
# BEGIN MainWP
# END MainWP
# Wordfence WAF
<IfModule LiteSpeed>
php_value auto_prepend_file '/home3/user/public_html/wordfence-waf.php'
</IfModule>
<IfModule lsapi_module>
php_value auto_prepend_file '/home3/user/public_html/wordfence-waf.php'
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END Wordfence WAF
You may use this rule with corrected syntax of consitions:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^doig\.website\.technology$ [NC]
RewriteCond %{THE_REQUEST} !/(min|support|dynamic-keyword-module-drupal8|dynamic-keyword-plugin-joomla|wp-content|wp-includes|wp-admin)/ [NC]
RewriteRule . https://www.webby.net.au%{REQUEST_URI} [NE,R=301,L]

.htaccess remove trailing slash before redirect

I am having trouble with removing the trailing slash when i redirect to another page.
See my code:
Redirect /contact example.com/page
When I run the code above it redirects me to example.com/page/ with a trailing slash.
I would like to know how I can remove the trailing slash from the url.
Full .htaccess:
# All explanations you could find in .htaccess.sample file
Redirect /configurator.html /box.html
Redirect /catalog/category/view/s/blog/id/9 http://www.example.nl/blog
Redirect /contact/index/ http://www.example.com/contact.html
Redirect /contact.html/post http://www.example.com/contact.html
DirectoryIndex index.php
<IfModule mod_php5.c>
php_value memory_limit 768M
php_value max_execution_time 18000
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
</IfModule>
<IfModule mod_php7.c>
php_value memory_limit 768M
php_value max_execution_time 18000
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_ssl.c>
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]

404 is not getting completed and hinders the next requests

I have an e-commerce website created using magento. Whenever there is a 404 not found error, the loading of the site stops (or rather it keeps on trying to get that specific resource) and it kind of freezes. Other links or pages are not accessible for some time. I can browse the website only after around a couple of minutes (~5 minutes may be). Below is the screenshot of the firebug 'net' panel. First one while loading. And next after 5 minutes.
My htaccess is as below, if that has something to do with it.
DirectoryIndex index.php
<IfModule mod_php5.c>
php_value memory_limit 8M
php_value max_execution_time 180
php_flag magic_quotes_gpc off
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
php_flag zend.ze1_compatibility_mode Off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_ssl.c>
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
AddDefaultCharset Off
<IfModule mod_expires.c>
ExpiresDefault "access plus 1 year"
</IfModule>
Order allow,deny
Allow from all
<Files RELEASE_NOTES.txt>
order allow,deny
deny from all
</Files>
ErrorDocument 404 /404.html
#SetEnv MAGE_IS_DEVELOPER_MODE "true"
This happens only when a resource is not found in the page. I'm confused where to look for a solution. Thanks for looking into. Moderators, you may please rephrase the title if needed.
The 404 page template had some images missing. I removed those and it started loading correctly.

You don't have permission to access /magento/

I've put on the host in magento in sub-folder /magento/ and when I try to open http://example.com/magento/ I got this error
Forbidden
You don't have permission to access /magento on this server.
I know is something from the .htaccess file because if I remove/rename it I can open it but I don't know what exactly can do this in .htaccess. Is someone had this problem before and can give some info how to fix it?
I'll post lines that are not commented in default .htaccess
DirectoryIndex index.php
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
php_flag zend.ze1_compatibility_mode Off
</IfModule>
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_ssl.c>
SSLOptions StdEnvVars
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
Order allow,deny
Allow from all
<Files RELEASE_NOTES.txt>
order allow,deny
deny from all
</Files>
This looks like file permission issue. Check if your web server has the rights to read and execute on that magento folder.

non-www to www .htaccess redirect not working? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
apache redirect from non www to www
I want my domain to redirect the non-www to the www version. For some reason the below code isn't working.
Any suggestions?
Most probably any easy fix, but I can't get it to work.
<ifmodule mod_deflate.c>
<filesmatch \.(css|html|js|php|xml)$>
setoutputfilter deflate
</filesmatch>
</ifmodule>
<ifmodule mod_security.c>
secfilterengine off
secfilterscanpost off
</ifmodule>
<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^trailerpulse.com/
RewriteRule (.*) http://www.trailerpulse.com/$1 [R=301,L]
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^([a-z]+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L]
</ifmodule>
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
<filesmatch \.(css|js|gif|jpe?g|png)$>
ExpiresDefault A604800
</filesmatch>
<filesmatch \.(html|xml)$>
ExpiresDefault A10800
</filesmatch>
</ifmodule>
FileEtag None
Options All -Indexes
ServerSignature Off
ErrorDocument 404 /error
Your rule is almost there. The only problem is that you have a trailing slash after the hostname, which would never appear in the "Host:" header of the request. Replace the / with $ and add [NC] flag to ignore case:
RewriteCond %{HTTP_HOST} ^trailerpulse.com$ [NC]
RewriteRule (.*) http://www.trailerpulse.com/$1 [R=301,L]

Resources