I have nginx on a Raspberry Pi. In /etc/nginx/sites-available/default, I replaced server{} with the following, and I can access /var/www/html/index.php using http://192.168.1.210/.
server {
listen 80;
server_name $domain_name;
root /var/www/html/;
index index.html index.htm;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location ~\.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
try_files $uri =404;
include fastcgi_params;
# if (!-e $request_filename){ rewrite ^(.*)$ /index.php break; }
}
}
I now wish to add some simple redirecting similar to Apache's
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
I added if (!-e $request_filename){ rewrite ^(.*)$ /index.php break; at the end (see the above commented out line) and placed http://192.168.1.210/page2 in the browser, however, the script still doesn't redirect to /var/www/html/index.php
How can I redirect any non-existing requests to index.php?
What you are trying to accomplish is to redirect files and directories that do not exist towards index.php?
This can be done by using:
try_files $uri $uri/ /index.php;
Or which makes more sense:
error_page 404 /index.php;
This will also redirect missing files, images, ...
Related
At the moment I have the following code in my Config of Apache2.
So on every request on
http://[ExternalAdress]/vis/vis
is redirected to
http://[InternalAdress]/vis
<IfModule mod_proxy.c>
ProxyRequests off
RewriteEngine On
redirectmatch ^/vis/$ /vis/
rewritecond %{REQUEST_URI} ^/vis/
rewriterule (.*) $1 [PT]
rewritecond %{HTTP_REFERER} http://[ExternalAdress]/vis/
rewriterule ^/(.*) /vis/$1 [PT]
ProxyPass /vis/ http://[InternalAdress]:8082/ nocanon timeout=10
ProxyPassReverse /vis/ http://[InternalAdress]:8082/ timeout=10
</IfModule>
<IfModule mod_proxy.c>
RewriteEngine On
Redirectmatch ^/socket.io$ /socket.io/
RewriteCond %{REQUEST_URI} ^/socket.io/
RewriteCond %{QUERY_STRING} transport=websocket
RewriteRule ^/(.*) /wss/$1 [PT]
ProxyPass /wss/ ws://[InternalAdress]:8082/ timeout=1200 Keepalive=On
#ProxyPassReverse / ws://[InternalAdress]:8082/
</IfModule>
But now I want to change my code so that only one specific URL will be redirected and others not.
For example:
http://[ExternalAdress]/vis/vis/index.html?abc#123 shall be redirected to
http://[InternalAdress]/vis/index.html?abc#123
but
http://[EnternalAdress]/vis/vis/index.html?def#456 shall not be redirected to anywhere
How has my code to be changed to be sure that only one specific URL will be redirected and others not?
Good day, i have redirected my site using .htaccess but my http://www.example.com would not load unless i manually add the https:// to it.
Here is what my .htaccess looks like;
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.feathersignature.com/$1 [R,L]
RewriteOptions inherit
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<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
# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php5_module>
php_value memory_limit 256M
php_value upload_max_filesize 50M
php_value post_max_size 50M
php_value max_execution_time 300
php_flag asp_tags Off
php_flag display_errors Off
php_value max_input_time 60
php_value max_input_vars 1000
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
php_value memory_limit 256M
php_value upload_max_filesize 50M
php_value post_max_size 50M
php_value max_execution_time 300
php_flag asp_tags Off
php_flag display_errors Off
php_value max_input_time 60
php_value max_input_vars 1000
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Please what can do to properly redirect my site? I am a new developer and i want to learn. Thank you
I have an strange issue, maybe somebody could help me. When I shared link's of my site (wordpress) vía facebook, everything is ok in PC, but in IPAD or cellullar, when I click in facebook link I get 403 forbidden error.
UPDATED: I think maybe error could be in .htaccess is blocking traffic from l.facebook.com/l.php
# BEGIN All In One WP Security
#AIOWPS_BLOCK_WP_FILE_ACCESS_START
<Files license.txt>
order allow,deny
deny from all
</files>
<Files wp-config-sample.php>
order allow,deny
deny from all
</Files>
<Files readme.html>
order allow,deny
deny from all
</Files>
#AIOWPS_BLOCK_WP_FILE_ACCESS_END
#AIOWPS_BASIC_HTACCESS_RULES_START
<Files .htaccess>
order allow,deny
deny from all
</Files>
ServerSignature Off
LimitRequestBody 10240000
<Files wp-config.php>
order allow,deny
deny from all
</Files>
#AIOWPS_BASIC_HTACCESS_RULES_END
#AIOWPS_DISABLE_INDEX_VIEWS_START
Options -Indexes
#AIOWPS_DISABLE_INDEX_VIEWS_END
#AIOWPS_DISABLE_TRACE_TRACK_START
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
#AIOWPS_DISABLE_TRACE_TRACK_END
#AIOWPS_FORBID_PROXY_COMMENTS_START
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
#AIOWPS_FORBID_PROXY_COMMENTS_END
#AIOWPS_DENY_BAD_QUERY_STRINGS_START
RewriteCond %{QUERY_STRING} tag= [NC,OR]
RewriteCond %{QUERY_STRING} ftp: [NC,OR]
RewriteCond %{QUERY_STRING} http: [NC,OR]
RewriteCond %{QUERY_STRING} https: [NC,OR]
RewriteCond %{QUERY_STRING} mosConfig [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(globals|encode|localhost|loopback).* [NC,OR]
RewriteCond %{QUERY_STRING} (\;|'|\"|%22).*(request|insert|union|declare|drop) [NC]
RewriteRule ^(.*)$ - [F,L]
#AIOWPS_DENY_BAD_QUERY_STRINGS_END
#AIOWPS_FIVE_G_BLACKLIST_START
# 5G BLACKLIST/FIREWALL (2013)
# # http://perishablepress.com/5g-blacklist-2013/
# 5G:[QUERY STRINGS]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (\"|%22).*(<|>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (javascript:).*(\;) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (\\|\.\./|`|='$|=%27$) [NC,OR]
RewriteCond %{QUERY_STRING} (\;|'|\"|%22).*(union|select|insert|drop|update|md5|benchmark|or|and|if) [NC,OR]
RewriteCond %{QUERY_STRING} (base64_encode|localhost|mosconfig) [NC,OR]
RewriteCond %{QUERY_STRING} (boot\.ini|echo.*kae|etc/passwd) [NC,OR]
RewriteCond %{QUERY_STRING} (GLOBALS|REQUEST)(=|\[|%) [NC]
RewriteRule .* - [F]
</IfModule>
# 5G:[USER AGENTS]
<IfModule mod_setenvif.c>
# SetEnvIfNoCase User-Agent ^$ keep_out
SetEnvIfNoCase User-Agent (binlar|casper|cmsworldmap|comodo|diavol|dotbot|feedfinder|flicky|ia_archiver|jakarta|kmccrew|nutch|planetwork|purebot|pycurl|skygrid|sucker|turnit|vikspider|zmeu) keep_out
<limit GET POST PUT>
Order Allow,Deny
Allow from all
Deny from env=keep_out
</limit>
</IfModule>
# 5G:[REQUEST STRINGS]
<IfModule mod_alias.c>
RedirectMatch 403 (https?|ftp|php)\://
RedirectMatch 403 /(https?|ima|ucp)/
RedirectMatch 403 /(Permanent|Better)$
RedirectMatch 403 (\=\\\'|\=\\%27|/\\\'/?|\)\.css\()$
RedirectMatch 403 (\,|\)\+|/\,/|\{0\}|\(/\(|\.\.\.|\+\+\+|\||\\\"\\\")
RedirectMatch 403 \.(cgi|asp|aspx|cfg|dll|exe|jsp|mdb|sql|ini|rar)$
RedirectMatch 403 /(contac|fpw|install|pingserver|register)\.php$
RedirectMatch 403 (base64|crossdomain|localhost|wwwroot|e107\_)
RedirectMatch 403 (eval\(|\_vti\_|\(null\)|echo.*kae|config\.xml)
RedirectMatch 403 \.well\-known/host\-meta
RedirectMatch 403 /function\.array\-rand
RedirectMatch 403 \)\;\$\(this\)\.html\(
RedirectMatch 403 proc/self/environ
RedirectMatch 403 msnbot\.htm\)\.\_
RedirectMatch 403 /ref\.outcontrol
RedirectMatch 403 com\_cropimage
RedirectMatch 403 indonesia\.htm
RedirectMatch 403 \{\$itemURL\}
RedirectMatch 403 function\(\)
RedirectMatch 403 labels\.rdf
RedirectMatch 403 /playing.php
RedirectMatch 403 muieblackcat
</IfModule>
# 5G:[REQUEST METHOD]
<ifModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
#AIOWPS_FIVE_G_BLACKLIST_END
# END All In One WP Security
# BEGIN WordPress
<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
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
# block visitors referred from semalt.com
RewriteEngine on
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]
Anybody Knows whats going on?
Thanks in advance
This is a partial answer. I received a question from someone I had not worked for before in that some of their viewers are also receiving the 403 error. I was not able to duplicate their error on any of my devices, but some of company's staff was able to reproduce the error. Specifically, it seems that the error is connected with the type of internet connection. To date, our tests indicate that it may have to do with using hot spots generated with i-devices. Commenting out the whole code block with the RedirectMatch 403 statements fixes the access, but we have not been able to isolate it to one line of code - turning them on and off and testing the site.
I have the following htaccess file for my ZF project.
SetEnv APPLICATION_ENV production
# Redirect old site pages
redirect 301 /The_GAPS_Postal_Application_20110126.pdf /pdf/The_GAPS_Postal_Application_20110126.pdf
redirect 301 /The_GAPS_Constitution.pdf /pdf/The_GAPS_Constitution.pdf
redirect 301 /The_GAPS_EJ_Postal_Application_20110126.pdf /pdf/The_GAPS_EJ_Postal_Application_20110126.pdf
redirect 301 /The_GAPS_Fishery_Rules.pdf /pdf/The_GAPS_Fishery_Rules.pdf
redirect 301 "/Gipping Angling and Preservation Society Waters.pdf" /pdf/Gipping_Angling_Preservation_Society_Waters.pdf
redirect 301 /gaps_waters.php /waters
redirect 301 /alderson_lakes.php /waters/alderson-lakes
redirect 301 /barham_b_pit.php /waters/barham-b-pit
redirect 301 /causeway_lakes.php /waters/causeway-lakes
redirect 301 /perch_pit.php /waters/perch-pit
redirect 301 /river_gipping_barham.php /waters/river-gipping-barham
redirect 301 /river_gipping_bramford.php /waters/river-gipping-bramford
redirect 301 /river_gipping_elton_water_bank.php /waters/river-gipping-elton-water-bank
redirect 301 /river_gipping_lagoon.php /waters/river-gipping-shamford-lagoon
redirect 301 /river_gipping_shamford_lock.php /waters/river-gipping-shamford-lock
redirect 301 /river_gipping_sproughton.php /waters/river-gipping-sproughton
redirect 301 /gaps_maps.php /waters/maps
redirect 301 /gaps_rules.php /waters/rules
redirect 301 /joining_gaps.php /membership
redirect 301 /gaps_postal_applications.php /membership/postal-applications
redirect 301 /joining_gaps_early.php /membership/join-early
redirect 301 /joining_caps.php /membership/join-caps
redirect 301 /gaps_guest_permits.php /membership/guest-permits
redirect 301 /gaps_officers.php /officers
redirect 301 /gaps_match_fixtures.php /matches/fixtures
redirect 301 /downloads.php /downloads
redirect 301 /links.php /links
redirect 301 /gaps_work_parties.php /work-parties
redirect 301 /constitution.php /constitution
RewriteEngine On
# Cached files
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cached/index.html -f
RewriteRule ^/*$ cached/index.html [L]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}\.html -f
RewriteRule .* cached/%{REQUEST_URI}\.html [L]
# Route to index.php for ZF
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
# Add compression
AddOutputFilterByType DEFLATE text/html
In my public_html folder I have a subfolder called lists containing a third party newsletter application. However calls to this folder just get redirected to the ZF application.
My question is how do I get the files in the lists folder to pass straight through rather than being directed to the ZF application?
I am building an app in Zend Framework at the moment and testing it all locally. I have Mamp Pro as my web server and I have a self-signed SSL which all seems to work. My problem comes when I try to do mod_rewrite - I just get 404 pages.
The way I have things set up (which may not be the best way...)
In Mamp I have 2 virtualhosts set up both pointing to the same web directory (webroot/public/):
secure.myapp.com
myapp.com
In my public directory is my index.php file and my .htaccess file. The contents of the .htaccess file are:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
When I visit http://myapp.com everything routes as it should using the mod_rewrite. But when I go to https://secure.myapp.com the index page is fine, but URL routing stops working and it appears to be that the .htaccess file is being ignored.
In my ssl.conf I have the following:
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost _default_:443>
SSLEngine on
DocumentRoot "/webroot/public"
ServerName secure.myapp.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
</IfModule>
Does anybody have any ideas on this? I'll be sooooo appreciative of the help as it's seriously hindering my development!
Well I'm pretty sure that I have got this working. Basically, a big problem I had is that Mamp does not store vhosts.conf as an accessible file. Instead this is an aliased application file.
I think what happens is that the virtualhosts are all dynamically created all on the standard http port, in my case 80. However I needed to be able to access the port 433 vhost config to enable FileInfo. So my workaround is to ditch my .htaccess file and stick the following ALL into my ssl.conf file.
<IfModule mod_ssl.c>
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout 300
SSLMutex file:/Applications/MAMP/logs/ssl_mutex
<VirtualHost mysite.com:443>
SSLEngine on
DocumentRoot /webroot/secure
ServerName mysite.com
ServerAdmin you#example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key
CustomLog /Applications/MAMP/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
RewriteLog /Applications/MAMP/logs/ssl_rewrite_log
RewriteLogLevel 3
</IfModule>
</VirtualHost>
</IfModule>
I had to add DOCUMENT_ROOT in front of my file and directory checks, and a forward slash in front of index.php. If I could have put this into a "Directory" then I think I could have avoided these changes, but Apache won't restart when I add this parameter.
The only thing I didn't try was adding the info to MAMP's httpd.conf, but I have a feeling the same restrictions may be in place.