I have the following .htaccess, and I'm trying to execute the /robots.txt in /public/robots.php.
I tried different ways, but my php script was not being executed...
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css application/x-javascript application/javascript text/html text/plain text/xml text/json application/json
</IfModule>
SetEnv APPLICATION_ENV "development"
php_flag magic_quotes_gpc off
php_flag register_globals off
php_flag short_open_tag on
RewriteEngine on
RewriteRule !\.(ico|js|css|jpeg|jpg|png|bmp|gif|pdf|doc|docx|xls|xlsx|xmlx|xml|pps|eml|txt|psd|flv|swf|fla|mp3|ttf|eot|svg|woff|zip)$ public/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]
How can I use a dynamic robots.txt, executing the /public/robots.php ?
Thx!
I fixed this problem with this htaccess:
<FilesMatch "^robots.txt$">
ForceType application/x-httpd-php
</FilesMatch>
Now, I'm able to execute the public/robots.txt as a php script. So, inside my public/robots.txt I'm able to test which server I'm using and create a dynamic robots.
Now when accessing the mysite.com/robots.txt the output is generated by public/robots.txt, executed as a PHP script.
Related
I added the following lines in the htaccess file in my download directory -
order Deny,Allow
Deny from all
Now I want to rewrite all URL from,
https://example.com/download/myfile.pdf
to
https://example.com/get-file.php?directory=download&request=myfile.pdf
Following is my htaccess file in web root -
RewriteEngine On
RewriteBase "/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteRule ^download/([A-Za-z0-9-.]*+)/?$ get-file.php?directory=download&request=$1 [NC,L]
ErrorDocument 404 /invalid-page-name
# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP
This does not work. Please can anyone tell me where I am making mistake? Many thanks for your help.
Please try to change
order Deny,Allow
Deny from all
to
<FilesMatch ".*">
Order Allow,Deny
Deny from All
</FilesMatch>
Regarding .htaccess file, what do i have to edit on the htaccess code to always direct to the https?
I have read other Q/A but my code seems to be larger than those
My website is on wordpress
DirectoryIndex index.php
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_mime.c>
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
# END W3TC Browser Cache
# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=W3TC_ENC:_gzip]
RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
RewriteRule .* - [E=W3TC_PREVIEW:_preview]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core
# 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
Using my website to replace example.com/yourdomain.com
The code to do so for the .htaccess file is:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^typrograms\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.typrograms.com/$1 [R,L]
Just look for code similar to this. If you don't see it, add it right underneath the RewriteEngine On
Just a little side note:Make sure your website supports HTTPS first! It won't work otherwise.
I think the code needs to go at top of page. (Above first # at-least)
This is my url mysite.com/screenshot/a/b/c/imgname.pl.jpg
Whenever I go to this url it redirects to not found.
<IfModule mod_rewrite.c>
RewriteEngine On
Options -Multiviews
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^screenshot/(.*)$ /screenshot/tempthumb.jpg [NC,L]
#it looks like htaccess is taking my url as a .pl perl file.
#So This is what I have tried.
RewriteRule ^screenshot/(.*)(.)(pl.jpg)$ /screenshot/$1\.$3 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.*)$ ./page.php?permalink=$1 [L]
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
</IfModule>
<IfModule mod_deflate.c>
<filesMatch "\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</filesMatch>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>
Ehat could be the problem
My guess as to what the problem could be is it's trying to look for a file called, literally, pl.jpg. Try making it into *.pl.jpg?
I can't figure out how to remove the string {jass_domain_name}/jass/jass.js?cb=47 from the end of my URLs using .htaccess. I've looked through a bunch of responses here and tried all of the following - they either crash the site or give me a js error.
RewriteCond %{REQUEST_URI} ^(.*)\{jass_domain_name}/jass/jass\.js\?cb=47(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_URI} ^(.*)Q\{jass_domain_name}/jass/jass.js?cb=47\E
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+){jass_domain_name}/jass/jass.js?cb=47$
RewriteRule ^(.*) http://www.elearnenglishlanguage.com/blog/%1 [R,L]
RewriteRule ^/(.*)\{(.*) http://www.elearnenglishlanguage.com/blog/$1
Thanks in advance for any advice.
ETA my /blog/.htaccess
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)%7Bjass_domain_name%7D/jass/jass\.js\?cb=47\sHTTP [NC]
RewriteRule ^ /%1? [L,NE,R=302]
#WFIPBLOCKS - Do not remove this line. Disable Web Caching in Wordfence to remove this data.
Order Deny,Allow
Deny from 54.74.250.230
Deny from 54.177.48.98
Deny from 54.177.53.123
Deny from 54.170.232.157
#Do not remove this line. Disable Web Caching in Wordfence to remove this data - WFIPBLOCKS
#WFCACHECODE - Do not remove this line. Disable Web Caching in Wordfence to remove this data.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
<IfModule mod_mime.c>
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
<IfModule mod_mime.c>
AddType text/html .html_gzip
AddEncoding gzip .html_gzip
AddType text/xml .xml_gzip
AddEncoding gzip .xml_gzip
</IfModule>
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.html_gzip$ no-gzip
SetEnvIfNoCase Request_URI \.xml_gzip$ no-gzip
</IfModule>
<IfModule mod_headers.c>
Header set Vary "Accept-Encoding, Cookie"
</IfModule>
<IfModule mod_rewrite.c>
#Prevents garbled chars in cached files if there is no default charset.
AddDefaultCharset utf-8
#Cache rules:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule .* - [E=WRDFNC_HTTPS:_https]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=WRDFNC_ENC:_gzip]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} ^(?:\d+=\d+)?$
RewriteCond %{REQUEST_URI} (?:\/|\.html)$ [NC]
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|wf_logout|wordpress_logged_in|wptouch_switch_toggle|wpmp_switcher) [NC]
RewriteCond %{REQUEST_URI} \/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)(.*)$
RewriteCond "%{DOCUMENT_ROOT}/blog/wp-content/wfcache/%{HTTP_HOST}_%1/%2~%3~%4~%5~%6_wfcache%{ENV:WRDFNC_HTTPS}.html%{ENV:WRDFNC_ENC}" -f
RewriteRule \/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)\/*([^\/]*)(.*)$ "/blog/wp-content/wfcache/%{HTTP_HOST}_blog/$1~$2~$3~$4~$5_wfcache%{ENV:WRDFNC_HTTPS}.html%{ENV:WRDFNC_ENC}" [L]
</IfModule>
#Do not remove this line. Disable Web caching in Wordfence to remove this data - WFCACHECODE
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
# prevent comment posting to requests with no referer
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*elearnenglishlanguage.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://www.elearnenglishlanguage.com/blog/$ [R=301,L]
You can use this rule as very first rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)%7Bjass_domain_name%7D/jass/jass\.js\?cb=47\sHTTP [NC]
RewriteRule ^ /%1? [L,NE,R=302]
/support-category/?category=category name
to:
/support/category/category name
This does not appear to be working:
RewriteRule ^support/category/$4 support-category/?category=$4 [nc]
Thank you :)
Also if I am getting the category name with a get request will that work when the link is accessed via the /support/category/category name format?
here's the entire .hatacces folder and it is located in the root directory of the site.
AuthName "Restricted Area"
AuthType Basic
AuthUserFile "/var/www/vhosts/xxx.de/dev.xxx.de/.htpasswd"
Require valid-user
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_mime.c>
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
# END W3TC Browser Cache
# BEGIN W3TC CDN
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
# END W3TC CDN
# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=W3TC_ENC:_gzip]
RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
RewriteRule .* - [E=W3TC_PREVIEW:_preview]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core
# 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]
RewriteRule ^support/category/([^/]+)$ support-category/?category=$1 [L,QSA,NC]
</IfModule>
# END WordPress
added this to functions.php
function rewrite_support() {
$wp_rewrite->flush_rules();
add_rewrite_rule('^support/category/([^/]+)/?$','support-category/?category=$matches[1]','top');
}
add_action( 'init', 'rewrite_support');
thanks
You can use:
RewriteEngine On
RewriteRule ^support/category/([^/]+)$ support-category/?category=$1 [L,QSA,NC]