.htaccess remove trailing slash before redirect - .htaccess

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]

Related

410 redirect url with dynamic GET parameters

Need make a redirect to 410 server response from this page - http://example.com/product_info.php?products_id=1
Tried many options, but they did not work, for example this:
RewriteCond %{QUERY_STRING} ^products_id=1$
RewriteRule ^.*$ - [G,NC]
For url's like this - http://example.com/?cat=79 work variant:
RewriteCond %{QUERY_STRING} /?cat=79
RewriteRule .* - [G,NC]
And accordingly this one too not work
RewriteCond %{QUERY_STRING} /?products_id=1
RewriteRule ^.*$ - [G,NC]
.htaccess file:
AddDefaultCharset utf-8
ErrorDocument 404 /404.html
ErrorDocument 410 default
RewriteEngine On
RewriteBase /
#SEO
RewriteRule ^index\.php$ /? [L,R=301]
#10.01.2018 Redirect index.php to /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
php_value default_charset UTF-8
php_value mbstring.internal_encoding UTF-8
</IfModule>
Working variant:
RewriteCond %{QUERY_STRING} (^|&)products_id\=1($|&)
RewriteRule .* - [G,NC]

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.

Redirect htaccess issue with pdf?

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.

htacess hotlinking question

My htaccess have this code
#
# Apache/PHP settings:
#
Options -Indexes
Options +FollowSymLinks
**# NOT WORKING #
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourwebdomain.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?friend1domain.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?friend2domain.com(/)?.*$ [NC]
# NOT WORKING #**
# Set the default handler.
DirectoryIndex index.php
# PHP5, Apache 1 and 2
<IfModule mod_php5.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value memory_limit 128M
php_value output_buffering 4096
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
# Modify the RewriteBase if you are using zina in a subdirectory and
# the rewrite rules are not working properly.
#RewriteBase /zina
# Rewrite current-style URLs of the form 'index.php?p=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
</IfModule>
How do i prevent hotlinking from other site for my mp3 and jpg file?
My url for download mp3 end as http://www.domain.com/music/cat_one/band_name/file_mp3_name.mp3?l=12
You could encapsulate your links to your mp3 and jpg files inside javscript functions. In this way, you do not have a link in html, but a user action (liking clicking on some element) will trigger a javascript which in turn loads the mp3 or jpg via i.e. ajax.
This will stop most hotlinking because the other website would have to emulate a user (which is not impossible, but most often probably not worth the effort).

Resources