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]
Related
I'm currently trying to make a htaccess thing to find the file in new/ if the request uri not contains api or list. I tried to do a thing like this but, it shows 403 error. Are there a easier way to filter, or?
RewriteEngine on
RewriteCond %{REQUEST_URI} /api/ [NC]
RewriteCond %{REQUEST_URI} /list/ [NC]
RewriteRule ^/(.*)$/ new/$1 [L, R]
Full htaccess code
#remove html file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
#remove php file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
#set max post size
php_value memory_limit 2048M
php_value max_execution_time 3000
php_value max_input_time 6000
php_value post_max_size 800M
php_value upload_max_filesize 200M
#Caching schema
<FilesMatch "\.(png|svg|css|eot|ttf|woff|woff2|otf|js|css)$">
Header set Cache-Control "public, max-age=86400000"
</FilesMatch>
DirectoryIndex index.html
#Custom 404 errors
ErrorDocument 404 /404.html
#Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
<Files error_log>
order allow,deny
deny from all
</Files>
#Prevent directory listings
Options All -Indexes
EDIT: With OP's full htaccess file please try following.
#remove html file extension
RewriteEngine on
##For external redirect rule.
RewriteCond %{THE_REQUEST} !\s/(?:api|list).*\s [NC]
RewriteRule ^(.*)/?$ new/$1 [L,R=301]
##For internal redirect rule.
RewriteRule ^new/(.*)/?$ $1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)/?$ $1.html [NC,L]
#remove php file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)/?$ $1.php [QSA,NC,L]
#set max post size
php_value memory_limit 2048M
php_value max_execution_time 3000
php_value max_input_time 6000
php_value post_max_size 800M
php_value upload_max_filesize 200M
#Caching schema
<FilesMatch "\.(png|svg|css|eot|ttf|woff|woff2|otf|js|css)$">
Header set Cache-Control "public, max-age=86400000"
</FilesMatch>
DirectoryIndex index.html
#Custom 404 errors
ErrorDocument 404 /404.html
#Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
<Files error_log>
order allow,deny
deny from all
</Files>
#Prevent directory listings
Options All -Indexes
With your shown attempts/rules, could you please try following once. Please make sure to clear browser cache before testing your URLs.
RewriteEngine on
##For external redirect rule.
RewriteCond %{REQUEST_URI} !^/(?:api|list)/? [NC]
RewriteRule ^(.*)/?$ new/$1 [L,R=301]
##For internal redirect rule.
RewriteRule ^new/(.*)/?$ $1 [L,NC]
OR try following rules set: Please make sure try only 1 set at a time, either above OR following.
RewriteEngine on
##For external redirect rule.
RewriteCond %{THE_REQUEST} !\s/(?:api|list).*\s [NC]
RewriteRule ^(.*)/?$ new/$1 [L,R=301]
##For internal redirect rule.
RewriteRule ^new/(.*)/?$ $1 [L,NC]
You may try these rules in your site root .htaccess:
RewriteEngine On
# redirect to /new if not /api, /list, /new and file exists in /new
RewriteCond %{THE_REQUEST} !\s/+(new|api|list)/ [NC]
RewriteCond %{DOCUMENT_ROOT}/new/$0 -f
RewriteRule .* /new/$0 [L,R=301,NE]
## remaining rules go below this line ##
# remove html file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L]
# remove php file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Make sure to test it after clearing your browser cache or test from a new browser.
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]
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.
my directory:
domain.com/
-----------subdomain/
---------------------subdirectory/
I've created subdomain as subdomain.domain.com
I need to access subdomain.domain.com/subdirectory but is shows: 404
I can access domain.com/subdomain/subdirectory/
please tell me how to do that.
### EDITED ###########
My .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA]
RewriteRule ^([0-9]+^)$ download/content/$1 [L]
<IfModule mod_php5.c>
php_value upload_max_filesize 200M
php_value post_max_size 200M
</IfModule>
if I add the following before my rule, it stops my existing. and if I add it after my rule. it doesn't execute because of [L] flag
RewriteCond %{HTTP_HOST} ^wap\.
RewriteRule !^wap/ wap%{REQUEST_URI} [L]
Have this rule in your root htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^wap\.
RewriteRule !^wap/ wap%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^([0-9]+)$ download/content/$1 [L]
<IfModule mod_php5.c>
php_value upload_max_filesize 200M
php_value post_max_size 200M
</IfModule>
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).