Response
stringlengths 8
2k
| Instruction
stringlengths 18
2k
| Prompt
stringlengths 14
160
|
---|---|---|
It appears i was missing this in my/etc/apache2/sites-enabled/000-default.conffile. After adding this and restartingapache, website runs fine.<Directory "/var/www/html/dist">
AllowOverride All
</Directory>ShareFollowansweredMar 27, 2017 at 4:49KanavKanav2,7851010 gold badges3636 silver badges5858 bronze badges21not working for me. I generated dist withng-buildand deployed in apache server,–Sathish KothaJul 19, 2017 at 12:55Thanks. And this approach works for the linode cloud server.–BharathirajaAug 21, 2018 at 17:30Add a comment| | I want to deploy an Angular 2 application on an Apache server. I've read various guides likethisandthisbut none of them is working. I havenpmandnginstalled on the server.In a nutshell, here's what I did:Cloned complete project repository on my server.Installed dependencies usingnpm install.Usedng build --prodcommand and it created adistdirectory.Changedapacheroot to/var/www/html/distdirectory.Enabledmod_rewrite, restartedapacheand added this.htaccessin mydistdirectory.<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>But only my home pagedomain.comworks, other pages likedomain.com/login,domain.com/registeretc. throw 404 error. Evendomain.com/index.html/logindoesn't work.The application works fine on my local system where I'm developing it usingng serve. What am i missing? | Deploy Angular 2 to Apache Server |
This line is setting the environment variable to the value of user authentication string - essentially setting a variable rather than constant value. As far as I know, SetEnv and SetEnvIf only allow you to set an environment variable to a predetermined constant.The variable being set is actually HTTP_AUTHORIZATION, not E. I would guess this is part of the user authentication process.ShareFollowansweredFeb 9, 2011 at 16:35WigeWige3,83888 gold badges3838 silver badges5959 bronze badges12You could useSetEnvIfinstead if you wanted to. In fact this might even be preferable if you have .htaccess files in subdirectories that use mod_rewrite (since you might override your authentication!). eg.SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0–DocRootMay 6, 2016 at 21:08Add a comment| | I have an rewrite recursion error somewhere on my website that Google Bot caused, but I can't find the url that caused it because my Loglevel is low. I raised it but it has not happened again so far.RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]All Rewriterules look fine to me and have the [L] flag, except this one.I can't quite understand it. It is from the open source shop system Magento.As far as I can tell it does nothing but sets the environment variable E. But isn't that a very stupid way of doing that? Shouldn't you use SetEnv if that was the goal? | What does this this HTTP Authorization RewriteRule do? |
Add this to the.htaccessfile:order deny,allow
deny from allShareFollowansweredFeb 18, 2011 at 20:20ChrisJChrisJ5,1912626 silver badges2020 bronze badges2Hmm, I've tried this: <directory /template> order deny,allow deny from all </directory> but I'm getting a misconfiguration error :(–Bv202Feb 18, 2011 at 20:25You must not use <directory>...</directory> in a .htaccess file. Just put the two lines above in the .htaccess.–ChrisJFeb 18, 2011 at 20:27Add a comment| | I have a folder with a lot of.phpfiles. I would like to deny access to them (using.htaccess). I know an option is to move this folder outsidepublic_html, but this is not possible in this situation.Is is possible to block access to a whole folder? | Prevent access to files in a certain folder |
This page from the apache docssays that you can do it like this:<FilesMatch \.(?i:csv)$>ShareFolloweditedNov 4, 2015 at 6:14hjpotter9279.7k3636 gold badges146146 silver badges187187 bronze badgesansweredMar 26, 2010 at 1:22Chad BirchChad Birch73.7k2323 gold badges152152 silver badges149149 bronze badges14This syntax also works with 'or' statements:"\.(?i:gif|jpe?g|png)$"–toddJul 12, 2017 at 18:02Add a comment| | This is a rule in my .htaccess# those CSV files are under the DOCROOT ... so let's hide 'em
<FilesMatch "\.CSV$">
Order Allow,Deny
Deny from all
</FilesMatch>I've noticed however that if there is a file with a lowercase or mixed case extension of CSV, it will be ignored by the rule and displayed.How do I make this case insensitive?I hope it doesn't come down to"\.(?:CSV|csv)$"(which I'm not sure would even work, and doesn't cover all bases)Note:The files are under the docroot, and are uploaded automatically there by a 3rd party service, so I'd prefer to implement a rule my end instead of bothering them. HadIset this site up though, I'd go for above the docroot.Thanks | How to make this .htaccess rule case insensitive? |
I'll consolidate my comments to this answer:When setting ...ErrorDocument 404 /404.phpthe/404.phppath may not be the absolute path to your htdocs folder root but instead the root of your filesystem. This may be, based on your configuration, e.g./home/htdocs/or~and so on.So what one need to do is find out the absolute path and set it accordingly.ShareFollowansweredApr 10, 2014 at 1:22conceptdeluxeconceptdeluxe3,84333 gold badges2626 silver badges3232 bronze badges11additional info: ie needs custom error page has > 512 bytes. details hereperishablepress.com/important-note-for-your-custom-error-pages–Andre ChenierJul 23, 2019 at 8:46Add a comment| | I have a.htaccessfile in the root directory and also 404.php file there. Content of my.htaccessfile is:ErrorDocument 404 /404.phpBut when I am mis-spelling my url,404.phpis not opening. Instead I am getting following message:Not FoundThe requested URL /mywebsite/ites.php was not found on this server.Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.But when I triedErrorDocument 404 google.com, it worked. | ErrorDocument 404 /404.php is not working in .htaccess file in PHP |
Changes to .htaccess are immediate and do not require a restart. Normally, if you aren't seeing what you expect from .htaccess changes, you have a syntax error and should check Apache's logs for some idea of what's going on.ShareFollowansweredOct 20, 2011 at 13:49Dirk DastardlyDirk Dastardly1,03722 gold badges1212 silver badges2323 bronze badges1link to documentationhttpd.apache.org/docs/2.2/configuring.html#htaccess–dev.e.loperOct 20, 2011 at 14:01Add a comment| | I have added url rewrite rules to my .htaccess file. Should I see these changes working right away? | How long does it take for .htaccess changes to take effect? |
TheErrorDocumentdirective, when supplied a local URL path, expects the path to be fully qualified from theDocumentRoot. In your case, this means that the actual path to theErrorDocumentisErrorDocument 404 /hellothere/error/404page.htmlShareFollowansweredOct 6, 2012 at 14:47StaticVariableStaticVariable5,25344 gold badges2525 silver badges4545 bronze badges3One more think , If in my index.php page I just add this line of code " header("HTTP/1.0 404 Not Found"); " It won't take me to 404 page, why is that ?–user1725155Oct 6, 2012 at 14:56@user1725155 you should read this articlecustom 404 not working–StaticVariableOct 6, 2012 at 15:00Many thanks, I was repeatedly trying to beat this into apache from the server root and not the document root.–dotParxFeb 8, 2019 at 15:43Add a comment| | I know this thread has been talked a lot on the web and here, and I tried almost all the methods, but still I'm having the same problem.This is my url on my local server ( MAMP )http://localhost:8888/hellothere/index.phpAnd I've tried to insert a wrong path to take me to wrong page , like below :http://localhost:8888/hellothere/eiurgiueribInstead of taking me to Error Page it shows :Not Found
The requested URL /hellothere/eiurgiuerib was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.My 404 page is inside of the Error directory. And inside my .htaccess file I have included this :ErrorDocument 404 /Error/404.php | Getting 404 Not Found error while trying to use ErrorDocument |
AuthUserFile /path/to/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-user
<Files "thubservice.php">
Satisfy Any
Allow from all
</Files>ShareFollowansweredOct 5, 2010 at 16:10talyrictalyric98322 gold badges1111 silver badges1515 bronze badges32+1 what I was typing. Youcoulddo it with a negative lookahead like<FilesMatch "^(?!thubservice\.php)">, but it'd probably be less efficient. Let's not drag regexen into it until we need to.–bobinceOct 5, 2010 at 16:12@talyric what if file is at path/to/file.php in folder. I tried giving the path but its not working...–MubinJul 15, 2020 at 10:09@Mubin Sorry, I don't know, and I don't have anything setup to try it on.–talyricJul 15, 2020 at 18:25Add a comment| | Part of my .htaccess file looks like this-AuthUserFile /path/to/.htpasswd
AuthName "Authorization Required"
AuthType Basic
require valid-userDoing that requires the Basic HTTP authentication for the entire directory and the directories below it as well. However, I have a single file within that root directory, thubservice.php, that should not require the HTTP authentication.From what I have seen, I need to use <FilesMatch />, but I cannot figure out the pattern to match all but that given file. | HTTP Basic Auth Exclude Single File |
You should be able to get the user name the user signed in with from the$_SERVER['REMOTE_USER']variable after they've successfully signed in.ShareFolloweditedJan 24, 2011 at 21:38answeredJan 24, 2011 at 21:19Michael IrigoyenMichael Irigoyen22.7k1818 gold badges9090 silver badges132132 bronze badges31From the PHP manual: "As of PHP 4.3.0, in order to prevent someone from writing a script which reveals the password for a page that was authenticated through a traditional external mechanism, the PHP_AUTH variables will not be set if external authentication is enabled for that particular page and safe mode is enabled. Regardless, REMOTE_USER can be used to identify the externally-authenticated user." We use$_SERVER['REMOTE_USER']on many of our pages and it works.–Michael IrigoyenJan 24, 2011 at 21:32It does say it on the page that advocatesPHP_AUTH_USER. I added my two cents aboutREMOTE_USERas to be another option/cover the special cases of external authentication. Link:php.net/manual/en/features.http-auth.php–Michael IrigoyenJan 24, 2011 at 21:381Chalk it up to a documentation difference between the two pages (sincethis doc page doesn't have it)...–ircmaxellJan 24, 2011 at 21:39Add a comment| | I'm constructing an upload so people I know can send me files securely, and with ease. But I want to design it just so, that when one of my friends sign in withtheirsign-in (it's going to an.htaccesslogin), I can establish that in PHP and log their file into a database associated with their account.In short, I need PHP to be able to detect who is signed in so I can pass that data to a database.Is there any possible way of doing that? | Use PHP to detect which htaccess user signed in? |
Because you provide a full URL in your rewrite rule it is automatically treated as a redirection. Replace the full URL with just a slash and it should work, i.e.:RewriteCond %{REQUEST_URI} ^/tour
RewriteRule ^(.*)$ / [P]You can even shorten it down to:RewriteEngine on
RewriteRule ^/?tour.* / [P]ShareFolloweditedFeb 15, 2013 at 14:16answeredFeb 15, 2013 at 13:41Michal MMichal M9,38288 gold badges4747 silver badges6363 bronze badges31You should inform of the risks of having mod_proxy enabled like Apache does herehttpd.apache.org/docs/current/mod/mod_proxy.html–user2602152Sep 4, 2015 at 11:19Thank you! This is what stuck me too. Makes sense.–XonatronFeb 15, 2020 at 15:43it works when I try to rewrite/fake-urlto a real file like/new.php, but when I try to rewrite/fake-urlto/another-fakewhile real isindex.phpit changes the url.–HebeApr 14, 2021 at 21:39Add a comment| | I would like to have a URL be redirected to a different page on the same domain but without the browser changing the URL. So the pagewww.mydomain.co.uk/tour/should point towardswww.mydomain.co.uk/but without changing.I have looked at a lot of similar questions on Stackoverflow but all the solutions seem to change the URL for me.CODE:RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_URI} ^/tour
RewriteRule ^(.*)$ http://www.mydomain.co.uk/ [L] | .htaccess: Redirect without changing url |
You can try to add a.htaccessfile in your React directory with that source code into it.<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>ShareFolloweditedDec 20, 2019 at 16:35samura4,37511 gold badge2020 silver badges2626 bronze badgesansweredOct 17, 2019 at 23:49rudi Ladeonrudi Ladeon67466 silver badges1212 bronze badges51May be you will get a blank page because the server didn't find your static directory modify the index.html file links like that /static/ to /subdirectory/static/.–rudi LadeonOct 18, 2019 at 0:322Works like a charm :D but don't forget to uncomment the module in conf. Ref.gist.github.com/alexsasharegan/173878f9d67055bfef63449fa7136042–Enrique FloresMar 30, 2020 at 20:20I am a front end dev. Any chance you guys would show the proper way to do this and force SSL? I've managed it before but have to search each time...thank you.–MegPhillips91Sep 6, 2020 at 8:57@MegPhillips91for ssl you can user certbot–Danys ChalifourMar 27, 2021 at 21:42@MegPhillips91 you can try using this command to redirect to https. RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$example.com/$1[R,L]–EbukaMay 7, 2021 at 2:49Add a comment| | I want to host my react app in a subdirectory on my shared hosting account. Ie in the directorydomain.com/mydirectory/. But when I typedomain.com/mydirectory/in the search bar it opens the index of the directory & not the React App itself.I have already created a build version for my app. Hence the index.html file is at the root of the directory with the static folder & all the other contents that where created during thereact-buildscript.How can I make it work properly ? How can I configure my .htaccess file or what fix should I consider ? | How do I configure my .htaccess file for React App in Subdirectory? |
TheErrorDocumentdirective, when supplied a local URL path, expects the path to be fully qualified from theDocumentRoot. In your case, this means that the actual path to theErrorDocumentisErrorDocument 404 /JinPortfolio/error/404page.htmlWhen you corrected it in your second try, the reason you see that page instead is becausehttp://localhost/error/404page.htmldoesn't exist, hence the bit about there being a 404 error in locating the error handling document.ShareFollowansweredAug 3, 2010 at 19:33Tim StoneTim Stone19.2k66 gold badges5656 silver badges6666 bronze badges1Just declare it in htaccess? I'v got Server error message!–Hendry TanakaOct 10, 2014 at 5:00Add a comment| | I am trying to create a custom 404 error for my website. I am testing this out using XAMPP on Windows.My directory structure is as follows:error\404page.html
index.php
.htaccessThe content of my .htaccess file is:ErrorDocument 404 error\404page.htmlThis produces the following result:However this is not working - is it something to do with the way the slashes are or how I should be referencing the error document?site site documents reside in a in a sub folder of the web root if that makes any difference to how I should reference?When I change the file to beErrorDocument 404 /error/404page.htmlI receive the following error message which isn't what is inside the html file I have linked - but it is different to what is listed above: | Custom 404 error issues with Apache - the ErrorDocument is 404 as well |
Here's what you can put in your .htacces fileOptions +FollowSymlinks
RewriteEngine On
RewriteBase /
SetEnvIfNoCase Referer "^$" bad_user
SetEnvIfNoCase User-Agent "^GbPlugin" bad_user
SetEnvIfNoCase User-Agent "^Wget" bad_user
SetEnvIfNoCase User-Agent "^EmailSiphon" bad_user
SetEnvIfNoCase User-Agent "^EmailWolf" bad_user
SetEnvIfNoCase User-Agent "^libwww-perl" bad_user
Deny from env=bad_userThis will return:HTTP request sent, awaiting response... 403 Forbidden
2011-09-10 11:15:48 ERROR 403: Forbidden.ShareFolloweditedSep 10, 2011 at 15:29answeredSep 10, 2011 at 15:05Book Of ZeusBook Of Zeus49.7k1818 gold badges174174 silver badges171171 bronze badges12Ok, thank you. Uploading now. I will inform the result. Vera–VeraSep 10, 2011 at 16:317An easy easy to test is to use wget. This is what the return said when I wget my site.–Book Of ZeusSep 10, 2011 at 16:32This line blocks accesses through Facebbok external hit:5092 "-" "facebookexternalhit/1.0 (+http://www.facebook.com/externalhit_uatext.php)", useragent is empty. I removed this line and testing again–VeraSep 11, 2011 at 0:09Sorry, forgert the line SetEnvIfNoCase Referer "^$" bad_user–VeraSep 11, 2011 at 0:162So if you remove the "SetEnvIfNoCase Referer "^$" bad_user" it's working?–Book Of ZeusSep 11, 2011 at 0:19|Show7more comments | A stranger bot (GbPlugin) is codifying the urls of the images and causing error 404.I tried to block the bot without success with this in the bottom of my .htaccess, but it didn't work.Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^GbPlugin [NC]
RewriteRule .* - [F,L]The log this below.201.26.16.9 - - [10/Sep/2011:00:06:05 -0300] "GET /wp%2Dcontent/themes/my_theme%2Dpremium/scripts/timthumb.php%3Fsrc%3Dhttp%3A%2F%2Fwww.example.com%2Fwp%2Dcontent%2Fuploads%2F2011%2F08%2Fmy_image_name.jpg%26w%3D100%26h%3D65%26zc%3D1%26q%3D100 HTTP/1.1" 404 1047 "-" "GbPlugin"Sorry for my language mistakes | Block by useragent or empty referer |
Change your .htaccess with this:Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# if request is not for the /sub-dir/
RewriteCond %{REQUEST_URI} !^/sub-dir/ [NC]
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>ShareFollowansweredMar 29, 2012 at 12:58anubhavaanubhava771k6666 gold badges582582 silver badges649649 bronze badges0Add a comment| | My main public_html directory has the following .htaccess rules:Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>The problem is, I then have a subdirectory called source, and I want that directory to just list the files within it (because there is no index file). The problem is the above parent directory's htaccess rules are causing no files in source to be shown in the directory index (it just lists a blank index).How can I solve this?THANKS | How to stop sub directory inheriting parent's htaccess rules |
Just had a similar issueResolved it by checking inhttpd.conf# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All <--- make sure this is not set to "None"It is worth bearing in mind I tried (from Mark's answer) the "put garbage in the .htaccess" which did give a server error - but even though it was being read, it wasn't being acted on due to no overrides allowed.ShareFolloweditedFeb 3, 2015 at 10:05answeredNov 24, 2013 at 21:33TimPTimP69455 silver badges1919 bronze badges4I am having this issue too but can't find am http.conf file anywhere. Should I definitely have one?–RGriffithsSep 25, 2015 at 12:34I think you should as its created during a default install. Note it is httpd.conf–TimPSep 28, 2015 at 12:111Thanks - found it. Accessed through the Xampp control panel. I was looking c:/ ..... path etc.–RGriffithsSep 28, 2015 at 23:231Usually after trying a garbage in the .htaccess to make sure it works, we start by checkingIfModuleis activated, then we add the simplest rule without any conditions (something likepath/pagetodirect/url) to make sure apache is working, then you can add your conditions one by one.–Ibrahim.HJul 26, 2021 at 18:12Add a comment| | i m using XAMPP but i m not able to use .htaccess file at local host. i m trying so many times.. Online working good. but local host showing[The requested URL was not found on this server]My root folder is reallocalhost/acre/real/property_available.php
localhost/acre/real/properties
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /acre/real/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^properties$ /property_available.php/$1 [NC,QSA]
</IfModule>Please | .htaccess not working on localhost with XAMPP |
IndexIgnore *The above would prevent all files from being listed. Here*acts as a wildcard. You could replace it with something more specific, if needed.ShareFollowansweredSep 5, 2009 at 1:49Alan Haggai AlaviAlan Haggai Alavi73.3k1919 gold badges104104 silver badges127127 bronze badges2replace*how? Let's say I have 3 files and 1 folder I want to hide (file1.jpg, some.pdf, else.html, i-am-a-folder)–OmarMay 29, 2015 at 23:41IndexIgnore doesn't disallow access to known file locations within the folder that it protects. An htaccess with:order allow,denydeny from allwould do a better job.–GTodorovMay 8, 2016 at 7:49Add a comment| | Is it possible to hide the folders in my root folder?
Just in case my index.php would disappear you know?Could I also show 404 error not found if someone requests them? | Hide folders with .htaccess |
This was my solution:RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]ShareFolloweditedJul 3, 2011 at 14:33Kev119k5353 gold badges302302 silver badges389389 bronze badgesansweredAug 5, 2009 at 5:17wessidewesside5,70055 gold badges3030 silver badges3535 bronze badges1This rule is not working for me. While I added your rule, The page will redirect to the welcome page ofxampp.–Tek KshetriApr 7, 2020 at 14:37Add a comment| | Ok, im pretty new at this and I would really appreciate some help, thanks!How can i rewrite this in .htaccess correctly?So I have a query string in my url:/?url=contactAll i want to do is remove the query string/contactHelp? I scoured google and I'm learning the syntax right now, but the fact remains..I dont know how to do it just yet. Thanks to all | htaccess rewrite for query string |
PNG is already a compressed data format. Compressing it with GZIP is not likely to decrease the size, and can in fact make it larger.I'm surprised you're seeing benefits when GZIP-ing JPGs, as they are also compressed.Seeherefor Google's tips on using GZIP. They recommend not applying it to images.ShareFolloweditedJun 13, 2017 at 17:06Matthias Braun33k2626 gold badges147147 silver badges174174 bronze badgesansweredJul 2, 2012 at 7:44Rob TrickeyRob Trickey1,3111212 silver badges1313 bronze badges0Add a comment| | I use following .htaccess to set gzip compression:AddOutputFilterByType DEFLATE text/html image/png image/jpeg text/css text/javascriptPlease check this url:http://www.coinex.com/cn/silver_panda/proof/china_1984_27_gram_silver_panda_coin/the gzip compression works for html, css, js and jpg, but not working for png (really amazing..) | why png size doesn't change after using http gzip compression |
You need a rewrite condition:RewriteCond %{HTTP_HOST} ^www.domain.com$before your rewrite rule.If you list several rewrite conditions before your rules, everyone of them must match for the RewriteRule to be executed, for example:RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{HTTP_HOST} ^www.domain2.com$which will of course NOT work, because the HTTP_HOST cannot contain simultaneously both values.You must then use the [OR] modifier:RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain2.com$so that the RewriteRule is executed if ANY of the above conditions match.Seehttp://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecondfor more information.ShareFolloweditedMay 28, 2012 at 14:43answeredMay 28, 2012 at 13:40SirDariusSirDarius42k88 gold badges8787 silver badges102102 bronze badgesAdd a comment| | I have this rule:RewriteRule ^(about|installation|mypages|privacy|terms)(/)*$
/index.php?kind=portal&id=1&page=$1&%{QUERY_STRING} [L]How can I change it so that it would work only for a specific domain,www.domain.comfor example? | How to make .htaccess RewriteCond check domain name? |
the following rule will match any URL ending in a slash and remove all slashes from the end of it:RewriteRule ^(.*)/+$ $1 [R=301,L]Note:The currently accepted answer only works for http not https but this one works for both.ShareFolloweditedJun 6, 2015 at 19:22answeredMar 30, 2013 at 12:40aleembaleemb31.7k1919 gold badges100100 silver badges114114 bronze badges6@steve The completed answer is obviously going to be worth the wait.–nickharJun 7, 2013 at 9:18I've refreshed this page for over 2 years now waiting for the answer ... This is the literally the last thing I need to do before putting my website live ...–Just Lucky ReallyJun 5, 2015 at 16:16Just noticed this today after so long. Maybe I should not have clarified to humour the other readers :)–aleembJun 6, 2015 at 19:281The regex should match at least one character before/, so\(.+)/+$, otherwise you get an infinite redirect loop when requesting/.–ironchickenSep 2, 2016 at 23:49@ironchicken Not if the rule is used in.htaccess(as stated in the question). However, by itself, the rule above would result in a malformed redirect if used in.htaccess!–MrWhiteSep 24, 2022 at 0:32|Show1more comment | I use mod_rewrite/.htaccess for pretty URLs.I'm using this condition/rule to eliminate trailing slashes (or rather: rewrite to the non-trailing-slash-URL, by a 301 redirect; I'm doing this to avoid duplicate content and because I like URLs with no trailing slashes better):RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]Working well so far. Only drawback:it also forwards"multiple-trailing-slash"-URLstonon-trailing-slash-URLs.Example:http://example.tld/foo/bar//////forwards tohttp://example.tld/foo/barwhile I only wanthttp://example.tld/foo/bar/to forward tohttp://example.tld/foo/bar.So, is it possible to only eliminate trailing slashes if it's actuallyjust onetrailing slash?Sorry if this is a somewhat annoying or weird question!Thanks. | mod_rewrite: remove trailing slash (only one!) |
Header add Strict-Transport-Security "max-age=157680000"http://httpd.apache.org/docs/2.0/mod/mod_headers.htmlShareFolloweditedJun 24, 2012 at 4:24Ry-♦221k5555 gold badges480480 silver badges485485 bronze badgesansweredOct 15, 2009 at 7:02stevensteven13.4k1616 gold badges4040 silver badges3939 bronze badges39I would add a check if the module is loaded.<br/> <IfModule mod_headers.c> Header add Strict-Transport-Security "max-age= 157680000" </IfModule>–Mike ChernevMay 11, 2015 at 14:15I would only test for module if the behavior is optional. Otherwise, it is more difficult to debug...–jehonSep 27, 2018 at 8:284Don't forget to activate the apache module headersa2enmod headers–That Brazilian GuyMar 2, 2019 at 14:12Add a comment| | I want to add a custom header to a phpbb installation without touching the code. (Using .htaccess)The header is:Strict-Transport-Security: max-age=157680000Any ideas? | Add a header to each request using .htaccess |
Note that this is a XAMPP-specific issue. XAMPP loads some additional configuration files located inXAMPP/etc/extra/that override httpd.conf. For me the offending file ishttp-userdir.confwhich applies rules for ~user requests and contains the lineAllowOverride FileInfo AuthConfig Limit Indexesand changing that line toAllowOverride Alldid indeed solve my issue.This only applies to files served from your /Sites/ directory on OS X. I don't know if the Windows version uses UserDir at all or even has a similar rule.ShareFolloweditedMay 18, 2013 at 21:10Roy3,59422 gold badges3030 silver badges3939 bronze badgesansweredOct 18, 2011 at 5:04Eli HuebertEli Huebert27133 silver badges66 bronze badges2In addition, you can readhttpd.apache.org/docs/current/es/mod/core.html#allowoverridetoo. That doc may help you to define specific values of AllowOverride ;)–kaleemsagardMar 26, 2014 at 23:04This was helpful in conjunction withthis answer.–Stephen NiedzielskiNov 23, 2014 at 20:40Add a comment| | I have this in my .htaccess:Options +FollowSymLinksAnd I get the following error in the apache error_log:.htaccess: Options not allowed hereHere's the part from my httpd.conf file:#htdocs symlinks here
<Directory /Users/you/code/my/folder>
Options All
AllowOverride All
</Directory>
<Directory />
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>So I'm setting Options All and AllowOverride All everywhere, but STILL I'm not allowed to set the option. Can anyone make sense of this?Thanks,
MrB | .htaccess "Options not allowed here" |
Irrespective ofR=301thereLflag meansLastand should be placed in rules when you want to mark end a particular rewrite rule.As per theofficial doc:The [L] flag causes mod_rewrite to stop processing the rule set. In
most contexts, this means that if the rule matches, no further rules
will be processed. This corresponds to the last command in Perl, or
the break command in C. Use this flag to indicate that the current
rule should be applied immediately without considering further rules.ShareFollowansweredSep 23, 2013 at 12:52anubhavaanubhava771k6666 gold badges582582 silver badges649649 bronze badges2Wouldn't an external redirect flag (R) automatically imply "last" (L)? I can't think of any cases in which you want to redirect but only after applying other rules.–Stephen OstermillerOct 31, 2017 at 19:532To answer my own comment, it doesn't imply that. The documentation says: "You will almost always want to use [R] in conjunction with [L] (that is, use [R,L]) " and goes on to say why not including the L often messes things up.–Stephen OstermillerOct 31, 2017 at 19:55Add a comment| | Can anyone share with me the difference between[R=301]and[R=301,L]in a 301 redirect? Which is best suited to redirect urls?While both works perfectly fine, I do noticed that[R=301,L]changes the URL to the new URL while[R=301]only redirects the contents.Can anyone share some insight on this please? | What's the difference between [R=301] and [R=301,L]? |
When permanently moving a web site, or a web page, best practice is to use a 301 redirect. 302s in this situation seem incorrect. By saying "temporary move" a 302 tells search engines to keep the old domain or page indexed, but it would be desireable for them to index the new location. People use 302 redirects in an effort to circumvent the Google aging delay. This workaround might have worked at some point, but it is not a current best practice.Ref:301 Vs 302 RedirectsShareFollowansweredJan 2, 2012 at 12:11Sudhir BastakotiSudhir Bastakoti99.7k1515 gold badges160160 silver badges166166 bronze badges0Add a comment| | I am creating rules in my .htaccess for mobile, or bad pages etc...I am using these rules:rewriterules badpage /goodpage.html [r=302]
rewriterules iphone /iphone.html [r=301]Which one is better to use?I know is temporary and permanent, but when a temporary becomes permanent, my understanding is both do the same thing so same result at the end.I would like to know what is the difference between the 301 and 302 on a browser and bots perspective. | .htaccess r=301 vs r=302 |
Like the comments above said: you need to run your php module asDynamic Shared Objectto make it work, as described in theApache PHP Request Hanlding DocumentationDSO considerations:libphp provides Apache directives such as php_$value and php_admin_$value.DSO is the only option where these directives will be valid inside .htaccess filesor httpd.conf. When these directives are compiled with the concurrent DSO patch, they should be named php4_$value and php5_$value instead.cgi, fcgi, suphp it will not work.ShareFolloweditedJun 20, 2020 at 9:12CommunityBot111 silver badgeansweredJun 10, 2012 at 15:40Harald BrinkhofHarald Brinkhof4,39511 gold badge2222 silver badges3232 bronze badgesAdd a comment| | When I am using.htaccessfor the following PHP settings, I am getting500 Internal Server Errorwhile accessing the website.the code in the.htaccessfile:php_flag display_errors off
php_flag log_errors onThe file permission for the.htaccessfile is 644I know that code above is correct. But when it showed me500 Internal Server Error, I tried different code (most probably wrong) too, but nothing worked. The different code tried are:php_value display_errors off
php_value log_errors onandphp_value display_errors 0
php_value log_errors 1What can be the cause of500 Internal Server Error?After learning from the comments on this question, I found that PHP settings on.htaccessdoes not work with FastCGI. So, to change PHP settings, I need to modify thephp.inior I need to do it in the php code. Is there any alternate way, when I don't have access to modifyphp.inifile and I don't want to individually modify all the PHP files? | 500 Internal Server Error when using .htaccess for PHP Settings |
Here an "ultimate"sample htaccess fileand Apache'srewriting guide.ShareFollowansweredOct 12, 2010 at 8:17Nev StokesNev Stokes9,36155 gold badges4343 silver badges4545 bronze badges1Afraid that I've never read any so I'm unable to recommend anything–Nev StokesOct 12, 2010 at 9:02Add a comment| | Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed10 years ago.Improve this questionI would like learn about .htaccess file, from the very basic to the complex portions. All its capacities, with blocking user, authentication, hiding files, redirection. So far I have only used them, but I want to learn about them, understand them. So that I will be able to create my own rule.Could you please guide me through this, and point me to the basic and expert guides or lessons or even books. Anything, from basic to complex. | Learning .htaccess [closed] |
Note to readers: the old answer doesn't work anymore.As of version 2.4, Apache no longer allows theRewriteLogLevelandRewriteLogdirectives. Now they're all bundled with the singleLogLeveldirective (seeLog Filesdocumentation), which supports module-specific log levels with prefixes andtrace[1-8]constants. To set the highest level of logging specifically for the rewrite module, you now use the following:LogLevel warn rewrite:trace8ShareFolloweditedMar 19, 2015 at 21:01David J65911 gold badge99 silver badges2525 bronze badgesansweredFeb 10, 2013 at 1:01Joshua HonigJoshua Honig13k88 gold badges5454 silver badges7676 bronze badges22where i can wright LogLevel warn rewrite:trace8 htaccess–xpredoSep 18, 2016 at 15:441/etc/apache2/apache2.conf–pmiguelpinto90Jun 24, 2022 at 14:31Add a comment| | I was wondering how to create and debug this kind of script that can become a bit of headache if you are not used to write them (like me).Do you use tool to create them?Any tips to debug what's going on instead of just create a local structure and see what's happening in the browser? | How to debug htaccess rewrite script |
No, you do not have to escape slashes. Forward slashes don't have any special meaning in regular expressions.The one common character that has bitten me in the past is?in query strings. That one you do have to escape.ShareFollowansweredAug 28, 2010 at 16:14John KugelmanJohn Kugelman355k6969 gold badges540540 silver badges582582 bronze badges2Thank you very much John for the quick reply =D A quick suppliment question John, if you don't mind, relating to your "?" comment. I know it has to be escaped (the questionmark) but what if it is on the right hand side of the rule? Say for example "RewriteRule ^/([a-z0-9]+)$ /index.php?query=$1" the questionmark on the righthand side (index.php?) does that have to be escaped? I know that it doesn't have to be, but you know, just making sure.–TrainTCAug 28, 2010 at 16:23Correct again. Only on the left side.–John KugelmanAug 28, 2010 at 16:35Add a comment| | With regards to the forward slash "/" when giving a regex to RewriteRule or RewriteCond, or anything else related to .htaccess in particular, is there a need to escape the forward slash?Here is an example of what I am trying to achieveRewriteEngine on
RewriteOptions inherit
RewriteBase /uk-m-directory/
RewriteRule ^(region|region\/|regions\/)$ regions [R=301,L]
RewriteRule ^(county|county\/|counties\/)$ counties [R=301,L]
RewriteRule ^(city|city\/|cities\/)$ cities [R=301,L]The above works fine, and it continues to work fine when I remove the backslashes as shown belowRewriteEngine on
RewriteOptions inherit
RewriteBase /uk-m-directory/
RewriteRule ^(region|region/|regions/)$ regions [R=301,L]
RewriteRule ^(county|county/|counties/)$ counties [R=301,L]
RewriteRule ^(city|city/|cities/)$ cities [R=301,L]Which one is the correct way? Are they both wrong?
Is there any special reason the forward slash should be escaped, or shouldn't?My guess is that the forward slash does not need to be escaped because it isn't a special character, as far as I know. But I just want to be sure.In case you're wondering the point of this code, it redirects city, county, and region (with or without a forward slash) to their plural equivalents. Furthermore if the plural has a forward slash it removes the forward slash. | Do you have to escape a forward slash when using mod_rewrite? |
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]If you want it to be done as a redirect instead of just a rewrite modify the[L]to[L,R]ShareFollowansweredMay 13, 2011 at 10:01James CJames C14.1k11 gold badge3535 silver badges4343 bronze badges31I went for RewriteRule ^(.*)\.html$ $1.php [R] as with the as the L flag seems to have problems with some of my other Rules. Thanks for the help!–MaxMay 13, 2011 at 10:314the L flag prevents is a 'stop' flag. any rule following it will not be executedhttpd.apache.org/docs/2.2/rewrite/flags.html–roberthuttingerNov 5, 2012 at 19:471This isn't working for me under Windows 8.1 and XAMPP 1.8.3. I ended up using: "RewriteRule ^(.*)\.html$ /$1.php [L]". Note that the only addition is a / before the $1.php part. Cheers.–Mario AwadJul 23, 2015 at 9:23Add a comment| | I want to update all the pages on a website to use include for the footer and header. So I have to change a lot of .html pages to .php.So i'm looking for a way to redirect all pages that end with .html to the same url but ending in .php. | redirect all .html extensions to .php |
+50A hack that I have used.# Apache 2.2
<IfModule !mod_authz_core.c>
Satisfy Any
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all granted
</IfModule>ShareFollowansweredFeb 26, 2013 at 5:09MarkMark38133 silver badges22 bronze badges21...or if that module is absent on both ends, but your local/stage server is win (and Apache 2.x) and your live is linux (and Apache 2.y), check for any other module difference, i.e.<IfModule !mod_win32.c>–Frank NNov 5, 2015 at 8:33fantastic answer. Everything seems to build for 2.4, but mine is 2.2, this allows forward compatibility!–KeithOct 14, 2016 at 3:34Add a comment| | tl;dr:How do I do the following in a .conf or .htaccess file:<IfApache22>
# Do A
</IfApache22>
<IfApache24>
# Do B
</IfApache24>Longer question:With Apache 2.4 the oldOrderget's deprecated in favor ofRequire.In my .htaccess files I have<FilesMatch "\.(long|list|file|types)$">
Order allow,deny
</FilesMatch>which means Apache fails to start unless I enableaccess_compat. While doing so presents a useful workaround, I want a solution that works with both syntaxes as the config will be distributed to a lot of servers. The question is how I can detect the current version of Apache and apply the correct directive.I intend to use the file for a framework that is distributed to and used by a lot of people, and I can't control/guarantee that they have or lack any particular server setup, which is why I'd like the file to be 2.2/2.4 "agnostic". | Detect Apache version in apache config? |
You could use theRedirectMatchdirective ofmod_alias:RedirectMatch 301 ^/calendar-for-groups/.*$ http://www.mywebsite.com/eventsOr withmod_rewrite:RewriteRule ^calendar-for-groups/ http://www.mywebsite.com/events [R=301,L]ShareFollowansweredJul 29, 2011 at 18:43FloernFloern33.7k2424 gold badges105105 silver badges121121 bronze badges2I've tried all the suggestions so far and...RedirectMatch 301 ^/calendar-for-groups/.*$ http://www.mywebsite.com/eventsworked like a charm. Thanks a million!–Bryan CaslerJul 30, 2011 at 8:15Hello @Floern Will this work in a buddypress site where I want to redirect all links going to any user but instead of the default tab, I want to choose a different tab. The current default tab leaves the body of the profile page blank. I want to redirect to the activity page. it is going to a profile page but doesn't choose the tab by default.–Rookie RecruitsApr 23, 2020 at 16:55Add a comment| | I have a site I recently upgraded. The old site had a calendar that created hundreds of pages, on the new site this has been replaced by an events page and those calendar URL's no longer exist. For months now I have been getting search engines pounding no longer existent pages like these ones.For example:page not found calendar-for-groups/2012-09-15/1093
page not found calendar-for-groups/2011-W09/77
page not found calendar-for-groups/2011-W27/77
page not found calendar-for-groups/2012-06-29/1093How can I use htaccess to redirect anywww.mywebsite.com/calendar-for-groups/*request towww.mywebsite.com/events? | How can I use htaccess to redirect paths with a wildcard character |
You can get what you need from the HTTP_HOSTRewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]This way it will get the host always without the subdomain.ShareFolloweditedMar 30, 2012 at 15:23answeredMar 30, 2012 at 15:17baynezybaynezy6,7471212 gold badges5050 silver badges7676 bronze badges61+1 but you should really change RewriteRule line to:RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]–anubhavaMar 30, 2012 at 15:202I don't think this answer will solve OP's issue concerning visitors receiving a warning, though.–Pierre-OlivierMar 30, 2012 at 15:3013@baynezy code will only redirect non-ssl connections. This does not solve your issue about redirectinghttps://www.mysite.comtohttps://mysite.comor visitors receiving a warning when visitinghttps://www.mysite.com–Pierre-OlivierMar 30, 2012 at 15:447does not solve thehttps://www.mysite.comredirection tohttps://mysite.comissue–Francis PMar 30, 2012 at 17:232I've searched for hours and this is the only answer that has worked. Keep in mind that the above comments are right though. This will work for almost every instance except if they start withhttps://www.and nothttp://www–bryanSep 4, 2014 at 2:26|Show1more comment | basically what i want is redirect al request to use HTTPS instead of httpI have this in my htaccess so far and it worked great:
Code:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</ifModule>today someone noticed that when going to:http://www.example.comit redirects to and shows an unsecure connection thingie.My ssl is setup for non www domain: mydomain.comSo i need to make sure all site requests are sent to non www and https:
It works fine if i put example.com it redirects tohttps://example.combut with www.example.com it goes to htts://www.example.com and shows the errorwhat do i need to add to my code to redirect www to non www and then to ssl
? | apache redirect http to https and www to non www |
I would put this into the domain's root directory:RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(subdirectory/.*)$ https://www.mydomain.com/$1 [R=301,L]ShareFollowansweredJan 21, 2011 at 19:23FloernFloern33.7k2424 gold badges105105 silver badges121121 bronze badges0Add a comment| | I'm trying to write a RewriteRule for my .htaccess file. Specifically, whenever a user accesses a specific subdirectory, I would like it to Rewrite to force an HTTPS connection.For example, whenever someone accesses:http://www.mydomain.com/subdirectory(and any other sub-directories of that "subdirectory").I'd like it to rewrite tohttps://www.mydomain.com/subdirectoryI've tried the following, but it appears to create a loop:RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/subdirectory/$1 [R=301,L]Also, this .htaccess file is placed in the root of my domain.Any ideas on how to modify my RewriteRule?Many Thanks! | .htaccess redirect subfolder to HTTPS |
Try theSetEnvdirective:SetEnv is_special foobarShareFollowansweredMar 4, 2009 at 20:33GumboGumbo649k110110 gold badges784784 silver badges846846 bronze badges7There it is! 'is_special' => string 'foobar' (length=6)–SeanDowneyMar 4, 2009 at 20:366Note that you need mod_env to do this.–GumboMar 4, 2009 at 20:371Try and avoid polluting the $_SERVER variable. I would recommend creating some sort of Registry class if you want to store global data.–Hawk KroegerMar 4, 2009 at 21:021Of course you can write on $_SERVER variable, it's recommended for server specified configuration (such as API key etc... Browser type detected, country detection etc...)–Thomas DecauxSep 4, 2013 at 14:10So it is not possible with just php code to randomly create a$_SERVERvariable and assign a value for it.–shasi kanthSep 11, 2014 at 12:58|Show2more comments | Is it possible using .htaccess or other apache powers to set a custom server value in the php array $_SERVER.for exampleif($_SERVER['is_special']) {
echo "Yeah for us!";
} else {
echo "No you fool!";
}I realize I ask a lot of questions that the answer is no so feel free to say so. | Setting a Php $_SERVER value ($_SERVER['something']) using Apache .htaccess |
You're using wrong web server configuration. Point your web server to apublicdirectory and restart it.ForApacheyou can use these directives:DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">Fornginx, you should change this line:root /path_to_laravel_project/public;After doing that, all Laravel files will not be accessible from browser anymore.ShareFolloweditedAug 22, 2016 at 15:36answeredMay 29, 2016 at 7:21Alexey MezeninAlexey Mezenin161k2626 gold badges297297 silver badges283283 bronze badges22But what about shared hosting? How do we do it there? @alexey-mezenin–TheManishJan 27, 2017 at 21:14should i make vhost or just can putDocumentRoot "/path_to_laravel_project/public"in .htaccess?–Ray CoderOct 22, 2020 at 11:05Add a comment| | I am using Laravel for web app. Uploaded everything on production and found out that some of the files can be directly accessed by url - for examplehttp://example.com/composer.jsonHow to avoid that direct access? | How to hide config files from direct access? |
For online testing of .htaccess (read: mod_rewrite) rules, try:http://htaccess.madewithlove.be/It shows you what and how rules are applied to the input URL.ShareFolloweditedFeb 14, 2012 at 8:18answeredFeb 14, 2012 at 8:07Salman ASalman A267k8282 gold badges433433 silver badges526526 bronze badgesAdd a comment| | Anyone have a graphical tool for developing mod_rewrite rules.Ideally it would display a pipeline of rewrites and then when given an instance of a uri would show the transforms as the get applied.It's always a pain to get them setup just right so any way of making it easier would help. | mod_rewrite GUI? |
I use something similar to this for my admin folder in wordpress:#redirect all https traffic to http, unless it is pointed at /checkout
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/checkout/?.*$
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]TheRewriteCond %{HTTPS} onportion may not work for all web servers. My webhost requiresRewriteCond %{HTTP:X-Forwarded-SSL} on, for instance.If you want to force the reverse, try:#redirect all http traffic to https, if it is pointed at /checkout
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/checkout/?.*$
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]If you want some alternate ways to do it, check outaskapache.ShareFolloweditedJul 20, 2009 at 19:23answeredJul 14, 2009 at 23:23Curtis TaskerCurtis Tasker11.3k22 gold badges2323 silver badges2323 bronze badges4I checked the code on my server, using both blocks listed above, and it works fine with no redirect loops.–Curtis TaskerJul 20, 2009 at 19:21+1. Great answer. TheRewriteCond %{HTTP:X-Forwarded-SSL} onwas needed in my case because I am using RackSpace's cloud sites.–Luke StevensonAug 15, 2011 at 0:192@wilmoore'ssuggestion to use%{SERVER_NAME}addition will be useful–antitoxicMay 10, 2012 at 10:113I had to use this check to get it to workRewriteCond %{HTTP:X-Forwarded-Proto} !https–gregn3Feb 10, 2016 at 17:09Add a comment| | We've got a shopping site which we're hosting on a shared host (Mediatemple Gridserver). Some parts of the site need to use HTTPS (checkout etc) but the rest should be using HTTP.Does anyone know how we can always force the correct use of HTTP/HTTPS for particular URLs? We've had it working in various states but we can't get a request for a page that should be on HTTP but is requested with HTTPS to switch back correctly.I've had a look around SO but couldn't find a suitable answer to this. | Correctly switching between HTTP and HTTPS using .htaccess |
In your.htaccessfile you can specify what document you want as your default 403 error document.ErrorDocument 403 /dir/file.htmlHere the directory is relative to the document root.ShareFolloweditedMar 9, 2020 at 10:36galoget72299 silver badges1515 bronze badgesansweredJan 2, 2012 at 17:25JK.JK.5,12611 gold badge2828 silver badges2626 bronze badges0Add a comment| | I created a .htaccess inside a directory in which I don't want the files to be directly accessed. It works and fires the default 403 page (Access forbidden!) of the Apache server. How can I create a custom 403 page? Thanks! | Custom Error 403 Page PHP |
Rails has a built-in helper for this, you could place this in your application controller:protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "admin" && password == "test"
end
endThen use a before_filter on any controllers you want to protect (or just stick it in the application controller to block the whole site):before_filter :authenticateThis method works on Nginx as well as Apache, which is an added bonus. It doesn't, however, work if you have full page caching enabled - as the visitor never hits the Rails stack; it won't kick in.EditJust noticed that you specified the /admin route. All my admin controllers inherit from an AdminController. You could set yours up like so:/app/controllers/admin/admin_controller.rbclass Admin::AdminController < ApplicationController
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "admin" && password == "test"
end
end
endThen have all your controllers extend the admin controller, eg:class Admin::ThingsController < Admin::AdminControllerMy routes are setup like so:map.namespace :admin do |admin|
admin.resources :things
endHope that helps.ShareFolloweditedMay 10, 2010 at 15:36answeredMay 10, 2010 at 12:40robotmayrobotmay1,3161414 silver badges2222 bronze badges1Very nice explanation!–blackbironAug 29, 2016 at 6:20Add a comment| | I want the /admin route on my rails app to be protected by using .htaccess password files - is this possible? | using htaccess password protection on rails? |
.htaccess directivesapply to that directory, and all subdirectories thereof, so you should disallow access in your DocumentRoot,http://sub.mydomain.com/.htaccess:Order deny,allow
Deny from allAnd override that in any specific subdirectories you would like to allow access to,http://sub.mydomain.com/test/.htaccess:Order allow,deny
Allow from allShareFolloweditedOct 4, 2011 at 15:28answeredOct 4, 2011 at 15:17nachitonachito7,00522 gold badges2626 silver badges4444 bronze badges3This is an untested assumption but you just need that second.htaccessin any subdirectory that is supposed to be web accessible–MattJun 4, 2014 at 15:08Doesn't work for me - adding .htaccess with "Allow from all" in a subdir still requires a password for it.–Paul FeakinsJun 11, 2021 at 16:14However, adding "Satisfy Any" in addition to the above did fix it.–Paul FeakinsJun 11, 2021 at 16:58Add a comment| | How can I deny access tohttp://sub.mydomain.com/, but allow for (completely)http://sub.mydomain.com/test(orhttp://sub.mydomain.com/test/)There is a magento back-end behindhttp://sub.mydomain.com/test/ | .htaccess. deny root, allow specific subfolder. Possible? |
you could extend the maximum execution time like this:ini_set('max_execution_time', 0);else edit your htaccessphp_value max_execution_time 0ShareFollowansweredApr 9, 2013 at 14:02Mayukh RoyMayukh Roy1,81533 gold badges1919 silver badges3131 bronze badges0Add a comment| | Help please! I've been retrieving listing in my system from database. But it has thousand listing until this error appear:Fatal error: Maximum execution time of 30 seconds exceededThis code is from my htaccessphp_value max_execution_time 3000
php_value upload_max_filesize 512M
php_value post_max_size 512M
php_value memory_limit 256M
php_value set_time_limit 0How can I resolve this? I'm using PHP and MYSQL. | Maximum execution time of 30 seconds exceeded |
This will allow either someone from IP 127.0.0.1orlogged as a valid user. Stick it either in your config or .htaccess file.<Files learn.php>
Satisfy any
Order deny,allow
Deny from all
Allow from 127.0.0.1
AuthType Basic
AuthName "private"
AuthUserFile /var/www/phpexperts.pro/.htpasswd
AuthGroupFile /dev/null
Require valid-user
</Files>IP Alone:<Files learn.php>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>That definitely answers your question.ShareFolloweditedFeb 26, 2014 at 19:46Shawn3,33988 gold badges4747 silver badges6666 bronze badgesansweredAug 30, 2010 at 22:08Theodore R. SmithTheodore R. Smith22.4k1313 gold badges6666 silver badges9292 bronze badges4Fastest answer response ever!–Theodore R. SmithAug 30, 2010 at 22:[email protected] : if I want to deny from one IP but allow from all others then what to write in htaccess?–sqlchildFeb 6, 2014 at 15:41Change toAllow from allDeny from IP_ADDRESS.–Theodore R. SmithFeb 7, 2014 at 18:[email protected], I tried your code but I am getting Access forbidden! from my ip address. I have to access the service.php page from my single ip. <Files service.php> Order deny, allow Deny from all Allow from 0.0.0.0 </Files>prnt.sc/vtkknw–user9437856Dec 1, 2020 at 12:41Add a comment| | I've look all over, but keeps running into same info that talks about directory level IP restriction, which usually looks something like this:Order Deny,Allow
Deny from all
Allow from 123.123.123.123Is it possible to have same type of access restriction tied to a page/document? | .htaccess: how to restrict access to a single file by IP? |
Classic CGI isn't the best way to use anything at all. With classic CGI server has tospawn a new process for every request.As for Python, you have few alternatives:mod_wsgimod_pythonfastcgistandalone Python web server (built-in,CherryPy,Tracd)standalone Python web server on non-standard port andmod_proxyin ApacheShareFolloweditedMar 10, 2009 at 13:14community wiki3 revsvartec3I wouldn't recommend simplehttpserver for an actual production webapp. It's more for having an embedded webserver in other applications. As a replacement, might I recommend cherrypy -cherrypy.org?–Jason BakerMar 10, 2009 at 12:44One could also note that you can use a different, smaller proxying webserver like nginx or lighttpd in place of apache.–epochwolfMar 10, 2009 at 13:392For shared hosting service users -- and that probably means most readers of this post -- this constraint isn't really relevant because such shared hosting configurations invariably use UID/GID access control to separate individual user accounts and therefor always spawn a separate process foranyscripted URI -- PHP, Python of whatever.–TerryEJan 24, 2012 at 16:02Add a comment| | I have been using PHP for years. Lately I've come across numerous forum posts stating thatPHP is outdated, that modern programming languages are easier, more secure, etc. etc.So, I decided tostart learning Python. Since I'm used to using PHP, I just started building pages by uploading an .htaccess file with:addtype text/html py
addhandler cgi-script .pyThen, my sample pages look like:#!/usr/bin/python
print "content-type: text/html\n\n"
print "html tags, more stuff, etc."This works fine. But, I came across a comment in a post that said thatCGI isn't the best way to use Python. Of course, it didn't mention whatisthe best way.Why is it that using CGI is not the best way to use Python? What is the alternative?Is there sometotally other wayto set up a simple Python site? Is there some completely different paradigm I should be looking at outside of .htaccess and .py files?RelatedPros and Cons of different approaches to web programming in PythonWhat’s a good lightweight Python MVC framework?(esp.,@Kevin Dangoor's answer)How do I use python for web development without relying on a framework?Python Web Framework - Not App Framework or CMS FrameworkPython web programming | Why avoid CGI for Python with LAMP hosting? |
For conditional settings there isSetEnvIf:SetEnvIf Host ^stage\.example\.com$ PYRO_ENV=stage
SetEnvIf Host ^(www\.)?example\.com$ PYRO_ENV=productionShareFolloweditedFeb 20, 2019 at 10:38xhienne6,00311 gold badge1616 silver badges3636 bronze badgesansweredOct 16, 2012 at 0:38Fabian SchmenglerFabian Schmengler24.3k99 gold badges7979 silver badges111111 bronze badges2So useful for Magento as well:SetEnvIf Host \.de MAGE_RUN_CODE=de(in our case we have internal and external URLs:example.deas well asexample.de.testing.local) - so this works for both.–AlexMay 22, 2013 at 14:33This is the best answer.–Dmitri PisarevOct 23, 2014 at 7:36Add a comment| | Is it possible to set a SetEnv variable in an .htaccess file differently depending on hostname?For example, I need my.htaccessfile to have the following value:SetEnv PYRO_ENV productionOn production boxes, and...SetEnv PYRO_ENV stageOn staging boxes. The.htaccessfile is version controlled, which is the reason I'm looking for a conditional solution. | Conditional SetEnv in .htaccess? |
You need the "QueryString Append" option:RewriteRule ^(.*)$ index.php?route=/$1 [QSA,L]Edit: Added @DonSeba's contribution, because it is correct.ShareFolloweditedJul 11, 2011 at 21:02answeredJul 11, 2011 at 20:56Kevin StrickerKevin Stricker17.2k55 gold badges4646 silver badges7171 bronze badges6Thanks! This seems to be working well. A quickie: It appears that the ending slash is required for$_GETparams to be caught. Would it be possible to have the cake and eat it, ie. be able to do bothwelcome/test?avar=1&welcome/test/?avar=1? Thanks!–IndustrialJul 11, 2011 at 21:02I'm not sure on that one. Could it be your missing variable name?–Kevin StrickerJul 11, 2011 at 21:05Tested and works fine without the enging slash here. Used it for JQuery UI Autocomplete, because that always appends thetermparameter.RewriteRule ^service/autocomplete/(.+)$ autocomplete.php?type=$2 [QSA,L].–w5lMar 20, 2012 at 16:52never saw that you refered to me in your answer, thank you :)–DonSebaJul 3, 2012 at 12:081Note the fact that there cannot be a space between the QSA,L. [QSA,L]–johnsnailsOct 14, 2013 at 4:47|Show1more comment | Apparently, my .htaccess rewrite eats up all$_GET-variables on my page:When accessing the URLhttp://192.168.1.1/welcome/test?getvar=trueand runningvar_dump($_GET)in my index.php file, I get this this output:array
'/welcome/test' => string '' (length=0)So no$_GET-data available and no sign of thegetvar-variable from my URL.Here's my .htaccess:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]What should I change to ensure that my rewrite is working as intended but$_GET-variables still are accessible? | .htaccess: GET variables are lost in rewrite |
You can set the variable in the header X-Frame-Options: Deny.All modern browsers support the X-Frame-Options header.The Facebook uses this header to disable iframe/framesets (also Javascript).If you have enabled the mod_headers in apache:.htaccessHeader set X-Frame-Options DENYBut, you can enable iframes come from the same origin.Header always append X-Frame-Options SAMEORIGINOr in Nginx:add_header X-Frame-Options Deny; #or SAMEORIGINBrowser compatibility:SourceInternet Explorer: 8.0Firefox (Gecko): 3.6.9 (1.9.2.9)Opera: 10.50Safari: 4.0Chrome: 4.1.249.1042ShareFollowansweredJul 25, 2012 at 6:55Dg JacquardDg Jacquard1,0901010 silver badges1010 bronze badges21i think, that this is the best way to do so. another appropriate way would be using php: header("X-Frame-Options: SAMEORIGIN")... js or referrers are pointless–emfiJan 15, 2014 at 14:461Note : The Header directive is in the mod_headers apache module. You need to make sure that module is loaded into the apache server.stackoverflow.com/a/19510208/2042775–sj59Aug 3, 2017 at 9:57Add a comment| | Recently my complete site is called in iframe by two other domains. I would like to block other sites, who are trying to show my site in iframe.How can i block that through .htaccess? | How to Block Iframe call |
Symbolic links are faster yes (like Aki said) but here's my thoughts on this.if you have images, css or js files then you don't need to rewrite or create symbolic links. You can use the full URL (eg/images/...) or use a common domain likei.domain.com(or anything you want) and refer all your JS, Images and CSS there. Eg:i.domain.com/logo.jpgorjs.domain.com/site.js.This way, you never have to think about rewriting rules or create links you might forget one day.This one is very easy to manage and maintain if you need to add images, change js or update your CSS since you only have one point of entry and automatically everything be updated.ShareFollowansweredDec 10, 2011 at 0:12Book Of ZeusBook Of Zeus49.7k1818 gold badges174174 silver badges171171 bronze badges0Add a comment| | I have a website with multiple folders and I was trying to fix them in my .htaccess. After a little while, I have a big .htaccess with rules that conflicts.Now every time I want to add a folder I have to add it to the .htaccess.I did some research and I found out I can create symbolic link instead, so no more .htaccessIn both solution I have to create or modify something so for me its the same result at the end but is it a better practice to create instead symbolic link ? | .htaccess or symbolic link (symlink) |
As I understand you want to process all non-images threw your php file. Right?If so, then here is what you need:Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
RewriteRule (.*) entryPoint.php [QSA]
</IfModule>Remember to add to delete any image extension you want!
If I misunderstood,Please tell me to correct my answer!ShareFolloweditedOct 12, 2012 at 16:00Pacerier87.8k107107 gold badges379379 silver badges638638 bronze badgesansweredAug 15, 2011 at 1:33undoneundone7,85744 gold badges4545 silver badges7171 bronze badges6nope, I want to process everything through that file EXCEPT images :)–user893856Aug 15, 2011 at 1:36thats right, it works now, but whats the difference between: RewriteRule (.*) entryPoint.php [QSA] and RewriteRule ^(.*)$ entryPoint.php [QSA]–user893856Aug 15, 2011 at 11:371@user893856 there is no different because both rewrite all path!–undoneAug 15, 2011 at 16:53newb question: can someone tell me where to put this file? at document root?–philx_xJan 15, 2016 at 15:051I would add CSS and JS to keep some stylesheet and javascript to work on a maintenance page:RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js)$–loretoparisiFeb 27, 2016 at 10:59|Show1more comment | I have an .htaccess file with the following contents:Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>With this, I wantallrequests to be redirected to the fileentryPoint.phpso that it can examine them:If there is no extension, is must be a moduleIf there's a .php, it's a hackingIf it's a .png, then it's a "safe" call.In case of images, I used to output headers, andfile_get_contents()their content. I figured out it's a bit slower than leaving adirectread.My question is:How to prevent this .htaccess from callingentryPoint.phpif there are references for images?Extra feedback on the code I already have is greatly appreciated! | How to redirect all requests to a file, except images using Apache? |
FilesMatch should only match filenames. You can place the.htaccessfile inside theskinsdirectory and it should look something like this:<FilesMatch "\.(jpg|png|gif)">
ExpiresDefault A2592000
</FilesMatch>Alternatively, inhttpd.conf, you could use:<Directory path_to_the_skins_dir>
<FilesMatch "\.(jpg|png|gif)">
ExpiresDefault A2592000
</FilesMatch>
</Directory>Good luck.ShareFolloweditedOct 3, 2019 at 12:53jamix5,54855 gold badges2727 silver badges3636 bronze badgesansweredMay 16, 2009 at 13:16arahayaarahaya1,02099 silver badges1111 bronze badges1Thanks very much for your help. I'll go for the multiple .htaccess files to save changing the main httpd.conf. Thanks again, Matt–fistameenyMay 19, 2009 at 16:02Add a comment| | I'm trying to cache some files using a .htaccess file for Apache2. I want to cache a particular folder longer than anything else, so i've been trying to use the FilesMatch directive like this:<FilesMatch "skins(.*)\.(jpg|png|gif)">ExpiresDefault A2592000</FilesMatch>I'm hoping to be able to cache all image files in the /skins/ directory and it's subdirectories. However, I can't quite get the regular expression to work - Apache just ignores it altogether.How do you match a folder with<FilesMatch>in a .htaccess file?Cheers,Matt | Apache FilesMatch - matching a folder in the regular expression |
+50Don't be lazy and change your relative URIs in your resources to root directory absolute pathing like/css/style.css. This is the best.You can get clever and use regex and replace all the files you need which would be like a few one liners and you're done. How many places could there be to change? And you should be using a template.This should work but I wouldn't go this way.RewriteRule ^detail/(css|js|img)/(.*)?$ /$1/$2 [L,QSA,R=301]ShareFolloweditedJul 17, 2019 at 16:42answeredOct 26, 2012 at 19:24Anthony HatzopoulosAnthony Hatzopoulos10.5k22 gold badges4040 silver badges5757 bronze badges4do you mean that i should use "Absolute Paths" in all my resources ? Rather than "Relatives"–Bhavesh GOct 27, 2012 at 10:082@BhaveshGangani kind of yes, butnotthe kind with the protocol and domainhttp://example.com/css/style.css, but this type of root directory absolute pathing:/css/style.css–Anthony HatzopoulosOct 29, 2012 at 13:20Would be great to have the comment clarification in the main body :)–JoeJul 9, 2019 at 11:101Thanks @Joe - I've made the improvement.–Anthony HatzopoulosJul 17, 2019 at 16:43Add a comment| | I've following rule for.htaccessOptions +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteRule ^detail/([0-9]+)/?$ detail.php?id=$1It redirectshttp://localhost/detail/123URL tohttp://localhost/detail.php?id=123. The page redirects successfully, but the problem isCSS, JS, and imagesare not loading,CSS, js files are located underhttp://localhost/css/andhttp://localhost/js/One solution is to useabsolute path(ex /CSS, or /js rather than just CSS/, /js but this does not seem a reliable solution since we've to change it on all files,Any other solution based on.htaccessrules, which is independent of editing all PHP files and let us use "relative paths"? | URL rewriting : css, js, and images not loading |
Use this curl option for the commandline-u "User:Password"More details about this parameter can be found fromhere.ShareFollowansweredJan 28, 2014 at 16:55Sabuj HassanSabuj Hassan38.8k1414 gold badges7979 silver badges8787 bronze badgesAdd a comment| | I am usingcURLto test some RESTful APIs. Some of these APIs are served from an Apache machine, and protected with user/password combination using simple.httaccessfiles.Is there a way to provide cURL with a username / password combination as arguments? | curl: provide user and password for apache .htaccess file |
Well I figured out you can set headers a different way using mod_rewrite making it much easier:RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|Baiduspider) [NC]
RewriteCond %{HTTP_REFERER} google [NC]
RewriteRule ^.*$ - [ENV=LONGCACHE:true]
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" env=LONGCACHE
Header set Pragma "no-cache" env=LONGCACHE
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" env=LONGCACHEShareFollowansweredApr 18, 2013 at 5:42GameDevGuruGameDevGuru1,11522 gold badges1212 silver badges2828 bronze badgesAdd a comment| | I would like.htaccessto perform the following code ONLY ifhttp_refereris from google (.com/ .ru/ .co.uk /.co.in/ etc.). Is this possible?<filesMatch ".(jpg|jpeg|png|gif)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</FilesMatch> | Is it possible to set headers conditionally? |
If you want to exclude files based on regular expressions, you could use FilesMatch instead of Files, e.g.:<FilesMatch ^((home|test|file)\.php$|mysecretfolder|asecretpicture\.jpe?g)$>
...
</FilesMatch>ShareFollowansweredFeb 2, 2010 at 9:37ResiduumResiduum12k77 gold badges4040 silver badges7070 bronze badges4Perfect, I love the piping for each file name, just what I wanted. Thank you.–oni-kunFeb 2, 2010 at 9:43Caveat: Use start and end of the string, if you want to exclude /test.php, but not /public/test.php or /test.php.bak–ResiduumFeb 2, 2010 at 9:582That is the most useful thing I've seen all week. Granted, it's just past 2pm on a Monday, but still.–ImperativeMar 24, 2014 at 21:081Caveat: Includingmysecretfolderin theFilesMatchdirectivewill notdeny access to all files within that directory.–jamixOct 21, 2019 at 12:43Add a comment| | I am able to disable access to a file with.htaccess, but I don't know how to disallow multiple files to be viewed (directly, not from includes)They are.phpfiles so I can't disable a file type.<FILES ... ?
</FILES>For example"home.php, file.php, test.php"how do I disallow access to all three files with that tag or similar? | .htaccess deny access to specific files? more than one |
neither Redirect nor RedirectMatch allow you to specify a query string for the redirect source.[Source]You have to use mod-rewrite for redirecting based on query string:RewriteCond %{QUERY_STRING} ^p=375$
RewriteRule (.*) http://www.example.org/content/MyNewPage? [R=301,L]ShareFolloweditedOct 20, 2013 at 8:29answeredOct 25, 2012 at 16:56undoneundone7,85744 gold badges4545 silver badges7171 bronze badges3Unfortunately I get redirected to a 404 page not found, and my URL is still stuck showingexample.org/?p=375. I can confirm that the "content/MyNewPage" does exist and works. I also can confirm that my RewriteRules are working because they work fine in Drupal.–user785179Oct 25, 2012 at 17:12Clear your browser's cache and try again, browsers cache301 Permanent redirects–undoneOct 25, 2012 at 17:16Good suggestion, but now Firefox says that it is redirecting as an endless loop. "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." The URL is coming out asexample.org/content/MyNewPage?p=375–user785179Oct 25, 2012 at 17:20Add a comment| | I successfully mass migrated a Wordpress site to Drupal. Unfortunately in Wordpress, the content URL's were something like www.example.org/?p=123. My domain is still the same, but I want to do a redirect viahtaccessas Drupal will not allow URL's to be www.example.org/?p=123. In other words, the content does not have the same URL as it did in Wordpress. For example, the new Drupal URL would be something likewww.example.org/content/MyNewPageI tried this in my .htaccess file and it does not workRedirect 301 /\?p=375 http://www.example.org/content/MyNewPageSo I tried the below, but it does not work either.Redirect 301 /\?p\=375 http://www.example.org/content/MyNewPageJust as a test, I tried the below and it worked.Redirect 301 http://www.example.org http://www.google.comI made sure that my Redirect rule is at the top of the list in my .htaccess so it will be evaluated first. How do I fix this? | How to redirect URLs based on query string? |
+50PHP code doesn't have to deal with SSL at all in such case.
Here applies classicalSoCprinciple: if you code doesn't explicitly work with connection (in WP it does not), you should leave protocol checking to web server.You should also avoid defining port in your rewrite rules. In case you're not using multisite WP setup, you could try:RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]ShareFollowansweredSep 7, 2015 at 20:47Evgeny SoynovEvgeny Soynov71433 silver badges1313 bronze badges12and if using Multi-Site?–T.ToduaFeb 4, 2018 at 14:47Add a comment| | If I edit thewp-config.phpI am supposed to add:define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);However, my website has.htaccessrules to force https and www across the entire website:Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^website.com
RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301]I know there are other rewriterules available, but again not sure which one is correct.Which of the following 3 should I be using inwp-config.php1 - Without isset(), with curly brackets, with server_portif ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}2 - Without curly brackets & without server_port?if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';3 - Are curly brackets needed/better or "more correct" & is server_port required?if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}I've found a few other slightly different variations of this all over the internet regarding wordpress SSL but I can't figure out what one is the correct/main one... | Correctly force SSL on wordpress via wp-config.php |
I thinkAddDefaultCharset utf-8is enough for all.Maybe better way is set encoding to files, which are using different charset than default.ShareFolloweditedJun 24, 2017 at 18:08Uwe Keim40.1k5858 gold badges179179 silver badges295295 bronze badgesansweredNov 14, 2012 at 15:19cjayhocjayho54544 silver badges77 bronze badges62Reading more I see a few respected sites saying... AddDefaultCharset UTF-8 will serve all files regardless of file extension. Time to test I guess–EricNov 14, 2012 at 18:49@Eric I am using that, never the less, the lack of a charset is detected on my css and js files on 3rd party tools.–Andres SKApr 3, 2015 at 16:00Adding this to an xml file didn't used the utf-8. AddingAddCharset UTF-8 .xmldid. Seethis.–machineaddictMay 4, 2015 at 7:087Thedocumentationsays "This directive specifies a default value for the media type charset parameter (the name of a character encoding) to be added to a responseif and only if the response's content-type is either text/plain or text/html". So this is NOT enough for all.–yankeeNov 1, 2016 at 12:121Where in my .htaccess do I need to place it? Should it go at the top, bottom or below something else?–Richard YoungNov 17, 2016 at 14:00|Show1more comment | For yslow page speed I want to remove my meta tag and put my encoding into the .htaccess file. Below are all the ways to do it I have read about. Which is the preferred way? Also is the language setting a good idea too - and if out side of the filesmatch will it apply to all file types?1)https://github.com/jancbeck/My-Wordpress-Boilerplate/blob/master/htaccess.txtAddDefaultCharset utf-8
AddCharset utf-8 .html .css .js
DefaultLanguage en-USvs2)http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html<filesMatch "\.(html|css|js)$">
AddDefaultCharset UTF-8
DefaultLanguage en-US
</filesMatch>vs3) I suspect this is all that's needed. But untested.AddCharset UTF-8 .html .css .js
DefaultLanguage en-US | htaccess UTF-8 encoding for .html, .css, .js - Whats the best way? |
The final structure is:var express = require('express'), url = require('url');
var app = express();
app.use(function(req, res, next) {
console.log('%s %s', req.method, req.url);
next();
});
app.configure(function() {
var pub_dir = __dirname + '/public';
app.set('port', process.env.PORT || 8080);
app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.static(pub_dir));
app.use(app.router);
});
app.get('/*', function(req, res) {
if (req.xhr) {
var pathname = url.parse(req.url).pathname;
res.sendfile('index.html', {root: __dirname + '/public' + pathname});
} else {
res.render('index');
}
});
app.listen(app.get('port'));Thanks everyone.
PD: Render html with module ejsShareFolloweditedAug 2, 2019 at 7:40Kenzoid29611 silver badge1616 bronze badgesansweredJun 28, 2013 at 17:43jicsjics2,05533 gold badges1616 silver badges2727 bronze badges0Add a comment| | Is it possible to build a code like this innode.js?<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond% {REQUEST_URI}! / (View) / [NC]
RewriteCond% {REQUEST_FILENAME}!-F
RewriteRule ^ (. *) $ Index.html [L, QSA]
</IfModule>url display a route is not "view" and also the file does not exist then writeindex.html.using something likeexpressorconnectUPDATE: I need a regular expression for!/(view)/in route forexpressinnode.js. | nodejs equivalent of this .htaccess |
And the correct answer iiiiis...RewriteRule ^(a|bunch|of|old|directories).* - [NC,L]
# all other requests will be forwarded to Cake
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]I still don't get why the index.php file in the root directory was called initially even with these directives in place. It is now located in/appRoot/app/views/pages/home.ctpand handled through Cake as well. With this in place now, I suppose this would have worked as well (slightly altered version of Mike's suggestion, untested):RewriteCond $1 !^(a|bunch|of|old|directories).*$ [NC]
RewriteRule ^(.*)$ app/webroot/$1 [L]ShareFolloweditedJan 9, 2013 at 5:34Rais Alam6,9981212 gold badges5454 silver badges8484 bronze badgesansweredAug 7, 2008 at 6:09deceze♦deceze516k8686 gold badges758758 silver badges904904 bronze badgesAdd a comment| | In an application that heavily relies on.htaccessRewriteRules for its PrettyURLs (CakePHP in my case), how do I correctly set up directives to exclude certain directories from this rewriting? That is:/appRoot/.htaccess
app/
static/By default, every request to/appRoot/*is being rewritten to be picked up byapp/webroot/index.php, where it's being analyzed and corresponding controller actions are being invoked. This is done by these directives in.htaccess:RewriteBase /appRoot
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]I now want to exclude a few directories like static/ from this rewriting. I tried thisbeforethe Cake RewriteRules:RewriteCond $1 ^(static|otherDir).*$ [NC]
RewriteRule (.*) - [L]It works in so far that requests are no longer rewritten, but nowallrequests are being skipped, even legitimate Cake requests which should not match^(static|otherDir).*$.I tried several variations of these rules but can't get it to work the way I want. | .htaccess directives to *not* redirect certain URLs |
Try:AddType application/x-httpd-php .html .htmUPDATE 1It may be PHP version specific. If you're using PHP5 try:AddType application/x-httpd-php5 .html .htmUPDATE 2Try:RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .htmlOr here's yet another alternative way to do this:<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>ShareFolloweditedJun 9, 2011 at 15:51answeredJun 9, 2011 at 15:19John CondeJohn Conde218k9999 gold badges459459 silver badges500500 bronze badges6I went ahead and tried that and when I went to reload the page, chrome downloaded a file called "download." This was working the other day so I'm stumped.–Ben GJun 9, 2011 at 15:34I am using PHP5, however chrome is still attempting to download a file after I make the change. I apologize for being clueless here, I'm fairly new to working within .htaccess. Is there any more information I can provide that would help answer the question more effectively?–Ben GJun 9, 2011 at 15:50I'm not much of a server admin so I am unsure why it isn't working for you. But I added another way to do this to my answer. Hopefully it helps.–John CondeJun 9, 2011 at 15:52Still not working. Thanks for your help, I may just have to contact the old webdev I just replaced to figure out what is causing his backend to do this.–Ben GJun 9, 2011 at 16:021RemoveHandler .html .htm AddType application/x-httpd-php5 .html .htmworked for me–raglanApr 10, 2014 at 20:32|Show1more comment | I have the included code in my .htaccess file but the php code I am attempting to include is not working.Options +Includes
AddType text/html .htm .html
AddHandler server-parsed .htm .html
AddType application/octet-stream .vcf
AddOutputFilterByType DEFLATE text/html text/htm text/plain text/css text/php text/javascript application/x-javascript | Server not parsing .html as PHP |
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]This code needs to be put at the top of your .htaccess file below RewriteEngine OnShareFolloweditedJan 14, 2021 at 11:30answeredAug 9, 2012 at 9:57SimonSimon5,57066 gold badges5252 silver badges8585 bronze badges92Don't think this works to turn www.mydomain.com into www.mydomain.com/–jeffkeeJul 17, 2013 at 1:061The root domain is not included. on the webserver themydomain.comandmydomain.comhave exactly the same URI. For SEO reasons, they are treated as the same for the root domain, with or without trailing slashes–maskieAug 5, 2013 at 3:052add ^$ in condition to avoid '/' at the end of domain RewriteCond %{REQUEST_URI} !(/$|\.|^$) RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]–mukundDec 17, 2013 at 6:12This code needs to be put at the top of your .htaccess file below RewriteEngine On–JamesDec 31, 2019 at 13:52Please mention in answer that it will work when you put these lines on top of .htaccess file.–Shakir BlouchDec 31, 2020 at 19:30|Show4more comments | I'm trying to get the following effect (using this local filehttp://localhost/[company_name]/[project_name]/.htaccess):http://localhost/[company_name]/[project_name]/page-1 (adds slash)
http://localhost/[company_name]/[project_name]/page-1/ (does nothing)
http://localhost/[company_name]/[project_name]/page-1/subpage-1 (adds slash)
http://www.example.com/page-1 (adds slash)<br />
http://www.example.com/page-1/ (does nothing)
etc.The thing I want to accomplish is that this .htaccess doesn't need the pathhttp://localhost/[company_name]/[project_name]/anymore so that I don't have to edit this each time it's been uploaded.RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]I found the code above here:Add Trailing Slash to URLs, but it only makes it possible to use the HOST dynamically and discards the path. Does someone a solution to accomplish this effect? | Add Trailing Slash .htaccess |
Thisblog postsuggests that the spam referrers manipulate Google Analytics and never actually visit your site, so blocking them is pointless. Google Analytics offersfilteringif you want to mitigate fake site hits.ShareFollowansweredDec 27, 2014 at 10:37ab7ab720122 silver badges55 bronze badges21GA Filtering is total BS. It only gets rid of so-called "known" robots and spiders. The unknown ones are the ones that wreak the most havoc.–3DomAug 30, 2015 at 9:39@3Dom You're thinking of the 'known bots and spiders' option, whereas the answerer is referring to the possibility of filtering traffic at the View level that doesn't (for example) match your hostname.–J BrazierMay 27, 2016 at 12:47Add a comment| | I have several websites that get daily around 5% of visits from spam referrers. There is one strange things I noticed about this referrers: they show in Google Analytics, but I cannot see them in my custom designed table where I insert all the visitors to the site, so I think that they only manipulate the GA code, never reaching the site itself.If you follow their link, they redirect you to some affiliates link.I don't know whether they have impact on my SEO/SERP, but I would like to get rid of them. May I do that viahtaccessfile?One peculiar aspect is that I get visitors from different forum like pages. E.g.:forum.topic221122.darodar.com,forum.topic125512.darodar.cometc., so I would like to block the fulldarodar.comdomain.Besidesdarodar.com, there are alsoeconom.coandiloveitaly.cothat are bothering my stats. Can I block them all fromhtaccess? | How to Block Spam Referrers like darodar.com from Accessing Website? |
If you have recently upgraded to a version of Apache greater than version 2.2, the authz_core error error might be coming from your httpd.conf or httpd-vhosts.conf file in the<Document>tags. mod_authz_core was introduced in Apache 2.3 and changed the way that access control is declared.So, for example, instead of the 2.2 way of configuring<Directory>...<Directory "C:/wamp">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>OrderandAllowdirectives have been replaced with theRequiredirective:<Directory "C:/wamp">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>Sourceshttp://www.andrejfarkas.com/2012/06/fun-with-wamp-server-and-apache-2-4-2/http://httpd.apache.org/docs/2.4/upgrading.htmlShareFolloweditedNov 7, 2012 at 10:24answeredNov 6, 2012 at 19:32MabbageMabbage77511 gold badge77 silver badges1212 bronze badges1Is there really no way to handle it without intruding into Apache's config file? The problem is that you must have root's privileges to do it....–TebeDec 13, 2014 at 0:26Add a comment| | I'm trying to host a php based application with the following .htaccess values.Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteBase /easydeposit
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]However, I keep facing the following two errors,[access_compat:error] [pid 25330:tid 27] AH01797: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/system/
[access_compat:error] [pid 25330:tid 27] AH01797: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/private/
[access_compat:error] [pid 25330:tid 27] AH01797: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/application/
[authz_core:error] [pid 25330:tid 27] AH01630: client denied by server configuration: /home/abc/opt/apache/htdocs/xyz/.htaccessI'm not sure why this is happening. Any help is appreciated. | Error with .htaccess and mod_rewrite |
Try this rule:RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]ShareFollowansweredJun 14, 2011 at 16:59GumboGumbo649k110110 gold badges784784 silver badges846846 bronze badges6I get the old "Connected is untrusted" message from the browser when I try visiting:https://www.mydomainname.co.ukusing the htaccess from the accepted answer above.http://mydomainname.co.ukandhttp://www.mydomainname.co.ukboth redirect fine. My certificate was generated formydomainname.co.uk. Any ideas (or any more information you need)?–JonJul 27, 2011 at 9:12@Jon: The TLS/SSL layer is on top of HTTP (HTTPS is also known as “HTTP over TLS/SSL”). So the TLS/SSL connection is established and certificate is validated before it is handed down to HTTP and the HTTP redirection takes place. You can’t fix that.–GumboJul 28, 2011 at 16:08Thanks for the update, just to confirm - there isnowork around? (At all, or that you know of?)–JonJul 29, 2011 at 9:11@Jon: No, there is no solution to this that I know of.–GumboJul 29, 2011 at 10:221This produces a redirect loop for me. I found this answer to work:stackoverflow.com/a/21467534/298218–bobsoapJun 16, 2015 at 17:32|Show1more comment | I'm trying to force a user to be redirected to the non-www website, and, force https.I've got this which sort of work, but doesn't force https, when http is entered.RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://site.com\.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]Any ideas on what I'm doing wrong? | Force non-www and https via htaccess |
Try to visit the website with Developers Console open (F12)Make sure you check "Disable cache" under "Network" tabThis will bypass 301 redirect cache onbrowser-side.ShareFolloweditedFeb 17, 2021 at 12:08answeredApr 1, 2017 at 14:37Lucas BustamanteLucas Bustamante16.4k99 gold badges9696 silver badges8989 bronze badges0Add a comment| | I stupidly did a 301 redirect on websiteA.com to websiteB.com. After removing it from the .htaccess file the redirect is still in operation. I tried from outside the local network and it is still redirecting. I have cleared my cache and tried a different browser.Does anybody have any suggestions?UPDATE:If I add a 302 redirect to this .htaccess file the site honours it. When I remove it, the old 301 redirect still happens..htaccess file for websiteA.com:# -- concrete5 urls start --
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# -- concrete5 urls end --
#RewriteCond %{HTTP_HOST} ^.*$
#RewriteRule ^/?$ "http\:\/\/www\.websiteB\.co\.uk\/" [R=301,L] | Cannot remove 301 redirect |
If you want the rule to only execute when the domain is"tz433.tld", you need this condition:RewriteCond %{HTTP_HOST} ^(www\.)?tz433\.tldAnd to redirect"jobs/"and"jobs"to"tz433.tld/about-us/jobs.html", you can try one of these:RewriteRule ^jobs/? /about-us/jobs.html [R=301,L]
# or
RewriteRule ^jobs/? http://tz433.tld/about-us/jobs.html [R=301,L]ShareFollowansweredAug 5, 2015 at 10:165ervant - techintel.github.io5ervant - techintel.github.io4,40977 gold badges4040 silver badges6868 bronze badges2@5ervant i want to do same but your solution isn't working for me i'm using wordpress though and i want to redirect a url if it has/for-your-practice/, can you please tell what could go wrong ? This is what i didRewriteRule ^for-your-practice/? /product-category/for-your-practice [R=301,L]–Habib RehmanNov 2, 2016 at 16:562@HabibRehman To redirectwww.example.com/for-your-practice/towww.example.com/product-category/for-your-practiceyou can use your directive. (Check your other directives if they have conflict to that directive.) To redirect allwww.example.com/for-your-practice/anythingpages towww.example.com/product-category/for-your-practiceyou can useRewriteRule ^for-your-practice/(.*) /product-category/for-your-practice [R=301,L]–5ervant - techintel.github.ioNov 3, 2016 at 13:28Add a comment| | I would like to have an alias and redirect the URLtz433.tld/jobs/to the pagetz433.tld/about-us/jobs/.This is what I've tried by far; it didn't work:RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.tz433\.tld/jobs/$
RewriteRule (.*) http://tz433.tld/about-us/jobs.html [R=301,L]The problem is, in this root path there are multiple domains, because it is a multisite typo3 installation. So something like "redirect/jobsto/about-us/jobs" isn't working because it should only happen for a specific domain (tz433).The next specific thing iswww.tz433.tldautomatically redirects totz433.tld. So it should also work withwww.tz433.tld/jobs/andtz433.tld/jobs. Both should redirect totz433.tld/about-us/jobs.html.How can I achieve that successfully? | redirect a specific url to another url with .htaccess |
Give it a try with:RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/{2,} [NC]
RewriteRule ^(.*) $1 [R=301,L]It should redirect to a single slash at the end of the domain.
And an improvement on yours:RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
RewriteRule . %1/%2 [R=301,L]ShareFollowansweredAug 29, 2013 at 17:24MarcelMarcel1,2781010 silver badges1212 bronze badges3Based off your answer, to replace multiple hyphens, I did: RewriteCond %{REQUEST_URI} ^(.*)--(.*)$ RewriteRule . %1-%2 [R=301,L] --works, thanks–Michael dApr 6, 2017 at 15:091@Marcel It doesn't seem to keep the query params in the url.–JunJan 30, 2020 at 18:41The first solution ^[A-Z]{3,}\s/{2,} works with N number of slashes without fail. However improvment suggested fails depending on number of slashes in the URL. Hence improvment is not useful instead buggy.–Sharad UpadhyayJun 15, 2023 at 2:12Add a comment| | I am using the following htaccess rul to remove double or more slashes from web urls:#remove double/more slashes in url
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]This is working fine for slashes occured in the middle of uris, such as, If use url:http://demo.codesamplez.com/html5//audioIts being redirected to proper single slahs url:http://demo.codesamplez.com/html5/audioBut if the url contains double slashes in the beginning, JUST AFTER the domain name, then there its not working, example:http://demo.codesamplez.com//html5/audioits not being redirected.How I can fix the above rule to work for this type of urls as well? Thanks. | Issue In Removing Double Or More Slashes From URL By .htaccess |
The problem is thatMultiViewsis enabled.MultiViewsautomatically adds extensions to any requested URLs, if possible. This has nothing to do with your RewriteRule; it just so happens that you were rewritingsetuptosetup.phpsoMultiViewsand your rule were doing the same thing.Add-MultiViewsto theOptionsdirective to disable it.ShareFolloweditedJan 23, 2015 at 9:40MrWhite44.7k88 gold badges6161 silver badges8585 bronze badgesansweredMar 23, 2011 at 1:45nitro2k01nitro2k017,64744 gold badges2626 silver badges3030 bronze badges2Debugging these types of issues can be the worst. So glad I found your answer early on =) +1–gerbzAug 10, 2015 at 22:371@nitro2k01 sorry but how exactly to do this? What is options directive? I'm on mamp pro local host, code igniter framework, mac yosemite.–angry kiwiDec 29, 2015 at 4:00Add a comment| | I had a .htaccess file doing a very simple rewrite of the page names. This is the contents of the file:Options +FollowSymlinks
RewriteEngine on
RewriteRule setup setup.php [NC]I now want to stop rewriting setup to setup.php - how do I do this? I've tried removing the line from the file, I've tried deleting the file and restarting apache, and it isstillrewriting setup to setup.php. How do I make it stop? It seems to be completely ignoring any other .htaccess file I create, and there's nothing being written to the error log. Is it caching the file somewhere? How do I stop it?I'm using apache2 on ubuntu. | htaccess file somehow being cached? |
Strictly speaking, .htaccess files only allow single-line comments: an hash character (#) at the beginning of a line lets the parser know that line should be ignored, i.e.:# this is a comment in an .htaccess file and many other scripting languagesHowever, from a practical perspective it is possible to wrap any number of contiguous lines in an IF block (available from Apache 2.4).
This effectively disables the lines within the block. For example:<IF "false">
...disabled directives...
</IF>That been said, a multi-line comment in many programming languages would allow more or less any content within it, i.e. plain english rather than viable code.
Conversely, the content of an IF block as mentioned above must be composed of proper .htaccess directives and regular single-line comments - an http 500 error will be generated otherwise.ShareFollowansweredJun 2, 2016 at 17:39manu3dmanu3d1,05111 gold badge99 silver badges2323 bronze badgesAdd a comment| | Is it possible to comment out one or more sections of an .htaccess file, like you would using /* and */ in various programming languages? | How to comment out whole sections of a .htaccess file? |
It seems that script withtype="module"does not fetch the javascript file with the required credentials data to authenticate the user by the server.Therefore you getHTTP/1.1 401 Authorization RequiredTo solve this issue, You can addcrossoriginattribute to the script tag:<script type="module" crossorigin src="./js/mymodule.js"></script>
<script type="module">
import * as mymodule from "./js/mymodule.js";
mymodule.runme();
</script>This will inform the browser to make "credentialed" request (request which aware of HTTP cookies and HTTP Authentication information).ShareFolloweditedDec 2, 2018 at 6:50answeredJan 4, 2018 at 18:17napuzbanapuzba6,15333 gold badges2121 silver badges3333 bronze badges1For an unknown reason, this actually worked. Why could enabling crossorigin would solve the 401 when loading a script from the same website/port ?–pixisNov 30, 2018 at 23:06Add a comment| | When I run the following JavasScript, I can successfully log in but not access the modules. How can I pass the authentication to them?Sample Code<DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script type="module">
import * as mymodule from "./js/mymodule.js";
mymodule.runme();
</script>
</body>
</html>Opening this with a .htaccess with basic authentication results inGET
[...]mymodule.js [HTTP/1.1 401 Authorization Required 1ms]on Firefox 54 (dom.moduleScripts.enabled, it works without .htaccess)..htaccessAuthType Basic
AuthName "Internal Area"
AuthUserFile /opt/.../.htpasswd
Require valid-user | Javascript ES6 modules not passing along .htaccess basic authentication |
I have found the answer and solution to this problem. Before, I did not know that php.ini resides where in wordpress files. Now I have found that file in wp-admin directory where I placed the codepost_max_size 33M
upload_max_filesize 32Mthen it worked. It increases the upload file size for my worpdress website. But, it is the same 2M as was before on cPanel.ShareFollowansweredApr 13, 2013 at 19:16sanasana41022 gold badges66 silver badges2424 bronze badges0Add a comment| | I am using cPanel of my website to increase maximum upload file size for wordpress media uploads. I have used the codes(found out from google) for this purpose wp-config.php, .htaccess but nothing is working. In my cPanel, there is no service for php configuration editor under software / services section or anywhere else. Please help what should I do?My .htaccess shows this code:# 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 WordPressI tried by placing the code:php_value upload_max_filesize 20M
php_value post_max_size 20Minside and outside # blocks, it gives 500 error rather. | How to increase Maximum Upload size in cPanel? |
To automatically add awwwto your domain name when there isn't a subdomain, add this to the htaccess file in your document root:RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]ShareFollowansweredSep 4, 2012 at 4:55Jon LinJon Lin143k2929 gold badges221221 silver badges220220 bronze badges8Thank you. This seems to work. Can you explain why the previous one didn't work in your opinion? I noticed it working; however, then noticed that my subdomain didnt work. Not sure if this was related or not or just propagation issues. I would love to learn more about what each line means of the 2 answers. Thanks!–kdjerniganSep 4, 2012 at 7:54@kdjernigan thewwwwas never added to the redirect, and the first condition matches a subdomain.–Jon LinSep 4, 2012 at 7:566Does this solution assume a TLD with only one dot? i.e. it won't work for.co.uk?–jezmckOct 11, 2013 at 11:121its checking only one dot in TLD to make it work with .co.uk you need to check two dots here is my quick solution RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$ just change this condition rest remain same–umefarooqJan 28, 2015 at 6:141@LWC the regex is only checking the domain and TLD, it won't know the difference between a "www" or any other subdomain. Thus if there is a subdomain, or a "www", the condition fails and the rule is skipped.–Jon LinAug 28, 2017 at 3:02|Show3more comments | I need any www. added automatically to my domain ONLY IF a subdomain is not already there. I do want subdomains to bypass this redirect.How can I do this? | .htaccess redirect - automatically add www. if no subdomain exists |
post_max_sizeandupload_max_filesizeare PHP.ini settings. You can set them either directly in PHP.ini or viaini_set. I don't know if this can be set with some Cake-internal tools as well.However, the error could also be caused by aset limit of the RequestBodyLength in Apache(assuming you are running under Apache).ShareFollowansweredSep 15, 2010 at 15:42GordonGordon314k7575 gold badges544544 silver badges562562 bronze badges55Additionally, everywhere that Apache bails withHTTP_REQUEST_ENTITY_TOO_LARGE, there's a log statement, so there should be a description of what exactly offended Apache about the size of the request in the error log.–Tim StoneSep 15, 2010 at 20:50Yes. But in CakePHP, in which file will I have to set it using ini_set?–gautamlakumSep 16, 2010 at 8:16@lakum In the bootstrap file. But like Travis points out below, some ini values cannot be set at runtime. I havent checked if this applies topost_max_sizeandupload_max_filesize.–GordonSep 16, 2010 at 8:223@TimStone Where can i see those logs? Have a godaddy apache server–Akash BudhiaFeb 14, 2014 at 7:47@TimStone what the form of the error message should be? I cannot find related error message in my error.log–petertcApr 11, 2016 at 6:49Add a comment| | In one of my CakePHP site, I got this error.Request Entity Too LargeI don't know what is the problem. I think the data that I am posting through form is too large. I searched this in search engine and got that I will have to increasepost_max_size. Be default I think it is set to 8M.But don't know how to increasepost_max_sizein CakePHP and what to do for it?Thanks. | Request Entity Too Large PHP |
Use the order the other way around, ie:order deny,allow
deny from all
allow from 127.0.0.1ShareFollowansweredAug 15, 2009 at 6:05dajobedajobe4,98811 gold badge3636 silver badges4141 bronze badges41Ah, thanks for pointing that out! Not sure why I did that.... Also, I found that I needed to allow the ip address of my server access and not localhost. I assume that's because I'm hitting the fully qualified (http://.....) address when using lynx in the cron job. Thanks for the help.–AnthonyAug 15, 2009 at 6:19Brilliant, I put my phone's IP into allow.Now I can do it. :)–SPGJul 22, 2011 at 9:299I think you should also allow from::1, because otherwise it may not let you in (Apache 2.4.7)–anestvJun 19, 2014 at 16:352What should i do if i want to add another IP address besides the Require Local? (for httpd-xampp.conf) I mean, i want to allow local access and one external IP. My file has originally "Require Local", below it i have added "allow from xxx.xxx.xxx.xx" but it doesn't work because it shows access denied to that IP.–PathrosJan 15, 2015 at 18:11Add a comment| | Here is the situation...I have a cron job scheduled to run that is used to backup my database. Because of the way php is installed, I'm having to use lynx to hit the php script that is performing the backup.Because this script has to live within my public_html folder I want to deny all requests except for the ones that come directly from my server (i.e.: localhost). Also, I'm assuming that the ip I'll be coming from is 127.0.0.1. I'm not exactly sure if that's true but I can't think of what else my ip would be in this situation. Am I right about the cron job running and hitting the script from 127.0.0.1?Here is what my .htaccess looks like:order allow,deny
deny from all
allow from 127.0.0.1As a result, I keep getting a 403 Forbidden. Which is what I want to do for everyone else except for myself. Maybe I'm going about this the wrong way... Does anyone see what I'm doing wrong? | .htaccess allow localhost problem |
You just needhome.phpin yourDirectoryIndexto make it works. Remember that this is using in .htaccess file of your root project:DirectoryIndex home.phpShareFollowansweredApr 3, 2013 at 5:04EliEli14.8k55 gold badges6060 silver badges7777 bronze badges25It applies to all sub folders. I want to apply only to the root folder only.–CodeManiacApr 3, 2013 at 5:44NB: This code will apply for all your sub folders. Use the below code instead of 'DirectoryIndex' . >>>>>>>> RewriteEngine on RewriteRule ^$ /yourfile.html [L]–NikzNov 13, 2019 at 10:28Add a comment| | I have websitehttp://mywebsite.comIf I hit this URL it take index.php and index.html as default page. How can I make home.php as default page.
I have tried this but not working by placing following code inside .htaccess file of public_htmlDirectoryIndex home.php index.html index.php | how to make default page home.php instead of index.html and index.php |
WhileGumbo's answer'sreasoning was correct, I could not get his RewriteRule to work.Adding another RewriteCond did it. The following was tested and works fine.RewriteCond %{REQUEST_URI} /nl/index.php$
RewriteCond %{QUERY_STRING} ^mID=24511&subID=0$
RewriteRule ^.*$ http://www.example.com/solutions/printsolutions.html [L,R=301]ShareFolloweditedMay 23, 2017 at 12:34CommunityBot111 silver badgeansweredAug 12, 2009 at 14:47Martijn HeemelsMartijn Heemels3,58955 gold badges3838 silver badges3838 bronze badges12The actual pattern forRewriteRuledepends on if it’s used in the server configuration or in a .htaccess file and where the .htaccess file is located.–GumboAug 12, 2009 at 14:51Add a comment| | I've built a new PHP site for a customer and want to redirect the top ranking Google results from the old site structure to the new one.I've put several dozen Redirect 301's in a .htaccess in the documentroot, and while some work fine I'm having issues with a bunch of others.This works fine:Redirect 301 /nl/flash/banner_new.swf http://www.example.com/actueel/nieuws.html?action=show&f_id=152This doesn't work! (leading to a 404 since the redirect is simply skipped):Redirect 301 /nl/index.php?mID=24511&subID=0 http://www.example.com/solutions/printsolutions.html
Redirect 301 /nl/index.php?mID=24512&subID=0 http://www.example.com/support/koppeling-met-omgeving.htmlThe redirects are mixed in the .htaccess file, and only the redirects with GET parameters appear to fail.Is there a workaround? Ignoring the failing redirects is not an option to the customer. Thanks for your thoughts. | Apache Redirect 301 fails when using GET parameters, such as ?blah= |
If you are using theRflag you are tellingmod_rewritethat an external redirect is what you want, therefore the browser is asked to make a new request and the address bar should change accordingly.Without theRflag, there is no redirect, but an Apache-internal request rewrite which is hidden from the browser. Thus, the address bar won't change. However, you cannot use internal redirects to external URIs for obvious reasons.Since you seem to use an internal redirect anyway, just remove theRflag and it should work:RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)$ ?url=$1 [L]ShareFollowansweredAug 20, 2009 at 7:30Ferdinand BeyerFerdinand Beyer65.9k1616 gold badges156156 silver badges145145 bronze badges13For external URIs you can proxy it, using the flag [P]–Vinko Vrsalovic♦Jul 2, 2013 at 10:34Add a comment| | I'm trying to write an.htaccessrule to redirect to a script, which further redirects somewhere else. Kind of like how URL shorteners work. However, Idon'twant the address bar to change during the.htaccesspart of the redirect. (It's okay for the script redirect to change the location.)I'm usingmod_rewrite, currently doing this:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /
RewriteRule (.+)$ "?url=$1" [L,R=301]Is there a flag or another method I can use to achieve what I'm trying to do?Addenda: The location bar doesn't change in Firefox as the redirects are happening, which is what I want to do. It just changes once to reflect the end point.Safari changes it at every step. Any way to avoid that? | .htaccess redirect without changing address bar |
If you are redirecting a subdomain to another domain then there shouldn't be anything else in the .htaccess file other than this.# This will redirect a subdomain to another domain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursubdomain\.yourdomain\.com$ [NC]
RewriteRule ^(.*) http://www.newdomain.com/$1 [L,R]ShareFollowansweredDec 21, 2012 at 13:01Simon HayterSimon Hayter3,1412828 silver badges5353 bronze badges5This did not work, I have tried this exact method previously but for some reason it wont seem to take. I am not sure why?? Any other ideas?–DanDec 27, 2012 at 9:34This works great, but I was wondering...do you know a way to do this without changing the URL? So the page redirects but still keepsyoursubdomain.yourdomain.comin the address bar.–jlewkovichJun 9, 2015 at 3:22@JLewkovich there is no way to do that. The idea of the address bar to is to tell people where they are. However You could iframe the other site.–Simon HayterJun 9, 2015 at 8:57Line 5-6 doesn't works. Are the first definitions affecting that.gist.github.com/santosh/134f7f3c36a6dd7f11f1–Santosh KumarJun 18, 2015 at 20:14@JLewkovich, this is done in the answer providedhere. You'll simply have to tweak it a bit for the subdomain.–Chris - JrJul 24, 2017 at 16:45Add a comment| | We need to run a few subdomains from our main site and we need to point these to external sites that deal with the admin required.I simply need to redirect a subdomain to an external URL using .htaccess and also any advise about where to put it in the .htaccess file e.g. right at the top, as i know this effects certain rewrite rules.I won't write what i think it should be as this just leads the answer down a specific route.Cheers Guys,Really appreciate it.Dan | .htaccess Redirect Subdomain to External URL |
Use the$to mark the end of the string and the?to mark the preceding expression to be repeated zero or one times:RewriteRule ^content/featured/?$ content/today.htmlBut I recommend you to stick to one notation and correct misspelled:# remove trailing slashes
RewriteRule (.*)/$ $1 [L,R=301]
# add trailing slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ $0/ [L,R=301]ShareFolloweditedFeb 12, 2009 at 9:03answeredFeb 12, 2009 at 8:45GumboGumbo649k110110 gold badges784784 silver badges846846 bronze badges2+1 mostly for the additional info, although I was gonna' give it to you anyway.–UnkwnTechFeb 12, 2009 at 9:101@JensTörnell$0contains the whole matched string.–GumboDec 20, 2012 at 13:49Add a comment| | What do I need to do to the following rewrite rule to make it so it works whether or not their is a slash at the end of the URL?ie.http://mydomain.com/content/featuredorhttp://mydomain.com/content/featured/RewriteRule ^content/featured/ /content/today.html | .htaccess with or without slash |
# Development
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{HTTP_HOST} ^localhost
RewriteRule ^(.*)$ /app/index.php?request=$1 [L,QSA]
# Staging
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{HTTP_HOST} ^staging.mydomain.com
RewriteRule ^(.*)$ /html/app/index.php?request=$1 [L,QSA]
# Production
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{HTTP_HOST} ^www.mydomain.com
RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]ShareFolloweditedDec 21, 2016 at 14:44answeredJul 20, 2011 at 15:28Dumitru CebanDumitru Ceban64044 silver badges88 bronze badges2Is%{REQUEST_HOST}outdated variable? I only found the equivalent%{HTTP_HOST}in the mod_rewrite documentation.–Johnny WongDec 21, 2016 at 2:14@JohnnyWong, yep, seems so:httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecondupdated the answer withHTTP_HOSTvar. Feel free to edit the answer in case you find any other issues, since I don't use apache since 2011 I think ;)–Dumitru CebanDec 21, 2016 at 14:44Add a comment| | I'm working on a app that uses url rewrites and has a specific .htaccess configuration. When working on the app I have three eviorments:Developent on my local machine (localhost)Staging (staging.mydomain.com)Production (www.mydomain.com)I am constantly pushing new upgrades to the staging and production environment and each time I overwrite the existing source code I have to go in an change the .htaccess file. Is there a way I can the .htaccess generic to the directory or have it automatically detect it's environment?My current .htaccess file is below. I just un-comment the sections between the different environments but would love to stop doing that...# Development
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ /app/index.php?request=$1 [L,QSA]
# Staging
# RewriteEngine on
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !=/favicon.ico
# RewriteRule ^(.*)$ /html/app/index.php?request=$1 [L,QSA]
# Production
# RewriteEngine on
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !=/favicon.ico
# RewriteRule ^(.*)$ /index.php?request=$1 [L,QSA]Thanks in advance!Chuck | .htaccess between developemt, staging, and production |
That would besomething like:RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteCond %{REQUEST_URI} !/mypage\.html$
RewriteRule .* http://www.anothersite.com/mypage.html [R=302,L]AsAndrewpoints out, the %{REQUEST_URI} condition avoids infinite loop if you redirect to the same domain.AsXoraxcommentsalmost 9 years later:You should not useREMOTE_HOST, it will fail in many case. You should useREMOTE_ADDR.Cf "difference betweenREMOTE_HOSTandREMOTE_ADDR"ShareFolloweditedAug 24, 2017 at 13:40answeredNov 16, 2008 at 0:36VonCVonC1.3m539539 gold badges4.6k4.6k silver badges5.4k5.4k bronze badges3Now that IPv6 is in the picture, I'm finding there are cases where the localhost IP address comes through as ::1, not always 127.0.0.1 -- not exactly sure when and why, but to handle that I think you need an additional condition:RewriteCond %{REMOTE_HOST} !^::1The colons should not require escapes -- not special characters for the rewrite engine regex, I don't believe.–Chris JohnsonNov 18, 2012 at 7:572You should not use REMOTE_HOST, it wiill fail in many case. You should use REMOTE_ADDR.stackoverflow.com/questions/3812166/…–XoraxAug 24, 2017 at 13:382@Xorax Thank. I have amended my 9-years old answer.–VonCAug 24, 2017 at 13:40Add a comment| | Basically I'm about to start work on a site and I'd like something that I can add into my .htaccess file (or elsewhere) that'll work like this pseudo code: (my ip will be in place of 127.0.0.1)if (visitors_ip <> 127.0.0.1)
redirectmatch ^(.*)$ http://www.example.com/under-construction.htmlHopefully that makes sense... | Want to redirect all visitors except for me |
Looking in the apache logs is the easiest way to debug .htaccess imho (adding rewriteLog Directive if necessary)About migrating: if you are not using any physical file paths inside .htaccess (i.e. /var/www/site/script.php) they should be working without problems. If this is not the case, first try to remove all options and leave only redirect directives, in this mode you can see if it's problem with server configuration which denies rewriting of default settings.Some referenceShareFollowansweredMar 21, 2009 at 12:09AlekcAlekc4,74266 gold badges3232 silver badges3535 bronze badges51It is good to know than "RewriteLog" does not work on shared hosting because it has to be turned on in the httpd.conf which is not accessible in this case.–NedkoJan 24, 2012 at 12:22So what are your options then?–thoni56Jan 27, 2012 at 11:09@ThomasNilsson, Rob Russell has a suggestion for rerouting rewrites into 301 redirects, and sending debug info back to the console:latenightpc.com/blog/archives/2007/09/05/…(I haven't tried it yet).–ericsocoAug 16, 2012 at 4:20More here:stackoverflow.com/questions/9153262/…including a recommendation tonotuse 301s.–ericsocoAug 16, 2012 at 4:23Note: RewriteLog is deprecated for Apache 2.4+. Seewiki.apache.org/httpd/RewriteLog–bryanbraunAug 1, 2015 at 21:25Add a comment| | I'm a self-taught coder and I like to debug by echoing suspicious variables and commenting out code.Lately, I've had to learn more about the .htaccess file. I need it to do things like interpret php scripts as php5, url rewriting, limit file upload size etc.... I have a lot of trouble debugging a .htaccess file. I often have to migrate PHP applications from one shared hosting environment to another. Sometimes this breaks the .htaccess file (or instead, something in the .htaccess file breaks the site). I check to make sure domain names are updated.Are there popular techniques for debugging a .htaccess file? Is it just look in the apache logs? Anything else? | Popular techniques to debug .htaccess |
As far as I know they both compress the same amount as zlib.output_compression uses gzip, which is based on DEFLATE.PHP's zlib output_compression will only work files passed through the PHP handler (i.e. .php files), but Apache's mod_deflate can work on any files (eg static CSS or JS).ShareFollowansweredApr 14, 2010 at 10:17dave1010dave101015.3k77 gold badges6767 silver badges6464 bronze badgesAdd a comment| | Can anyone tell me the difference between using mod_deflate and zlib output_compression?I understand that zlib is done in PHP and mod_deflate is done in Apace, my .htaccess file looks like:php_flag zlib.output_compression Onor:SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|gif)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-varyAdvantages/disadvantages of either? | Difference between mod_deflate and zlib output_compression |
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1.com [OR]
RewriteCond %{HTTP_HOST} ^domain2.com [OR]
RewriteCond %{HTTP_HOST} ^domain3.com [OR]
RewriteCond %{HTTP_HOST} ^domain4.com [OR]
RewriteCond %{HTTP_HOST} ^domain5.com
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=permanent,L]This will redirect all your 18 domains to your new single domainwww.newdomain.com.Otherwise you can use following code to redirect each domain if they are on separate hosting:RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=permanent,L]ShareFolloweditedJun 19, 2021 at 1:01Nico W.10311 silver badge77 bronze badgesansweredJun 29, 2013 at 12:12Muddassar AhmadMuddassar Ahmad51644 silver badges88 bronze badges33Domains with leadingwwwwill not be affected by this. You can include such domains by using:RewriteCond %{HTTP_HOST} ^/?(?:www\.)?domain1.com–AvatarNov 9, 2016 at 8:47Can you explain why this doesn't work when the final domain is "https" and one of the domains is the same name egbob.comand the final rule ishttps://www.bob.com- it returns a mis-configuration error–PandaWoodMar 25, 2018 at 1:59And how can I handle it if somebody is calling one of my domains with https? E.g.domain1.com.–Patrick MünsterJul 4, 2018 at 16:15Add a comment| | I have about 18 domains that need to be redirected to a new one. It has to work both with or without www prepended.I've tried this:<IfModule mod_rewrite.c>
RewriteEngine on
Rewritecond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>That gives me a redirect loop (and only works with www before, i think?). | Redirect multiple domains to one domain (with or without www before) |
I just ran into this and here's the solution I came up with. I prefer this method because it doesn't redirect any subdirectory.RewriteCond %{REQUEST_URI} ^/root-directory[/]?
RewriteCond %{REQUEST_URI} !^/root-directory/+[/]?
RewriteRule (.*) http://www.example.com/ [R=301,L]ShareFolloweditedDec 31, 2016 at 4:50Cœur37.8k2525 gold badges200200 silver badges273273 bronze badgesansweredFeb 6, 2013 at 16:53JestepJestep98322 gold badges88 silver badges2121 bronze badges23billynoah's answer below is a better and cleaner solution for this.–JestepJul 23, 2013 at 21:27I would like to redirect only home to another site. not sub pages.example.comtonewsite.com–Prabu GunaJan 8, 2016 at 6:26Add a comment| | I need to redirect from:http://example.com/foldertohttp://example.com/newfolderBut leave:http://example.com/folder/subfolderWhere it is. Is this possible? I can't seem to make it happen without causing a heap of redirect chaos. | htaccess 301 redirect folder, but not subfolders |
Make sure that the.htaccessfile is readable byapache:chmod 644 access/folder_name/.htaccessAnd make sure the directory which contains.htaccessis readable and executable:chmod 755 access/folder_name/ShareFolloweditedApr 19, 2017 at 7:59javaDeveloper1,42333 gold badges2828 silver badges4444 bronze badgesansweredApr 19, 2017 at 6:07Roshan KumaraRoshan Kumara41133 silver badges44 bronze badges22In my case the directory was set 750, then chmoded to 755 and it worked.–HeitorJul 25, 2017 at 7:301@DakshShah On the server, where the web is hosted. You should have your FTP credentials available in hosting overview.–QwertyMar 4, 2018 at 10:37Add a comment| | 403 FORBIDDENYou don't have permission toaccess/folder_name/index.phpon this server.Server unable to read.htaccessfile, denying access to be safeAdditionally, a 403 Forbidden error was encountered while trying to use anErrorDocumentto handle the request.Here is.htaccesscode:<Files 403.shtml>
order allow,
deny allow from all
</Files>And I also tried another code:<Directory "/path/to/source/file/directory/www">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>But I am confused on the line "path/to/source/file/directory/www". | Server unable to read htaccess file, denying access to be safe |
To exclude a file, try something like this:RewriteCond %{REQUEST_URI} !^/pureplantessentials\.html$The rule will be skipped if the file ispureplantessentials.html.ShareFolloweditedDec 23, 2012 at 2:09answeredDec 23, 2012 at 1:48Felipe Alameda AFelipe Alameda A11.8k33 gold badges3030 silver badges3737 bronze badges8it is still rewriting. Is there a specific place it should be? I put it at the end of my exclusions...–ChristianDec 23, 2012 at 2:22That's why an example is important. Please update your answer with an example to see how the incoming URL with the file to exclude looks.–Felipe Alameda ADec 23, 2012 at 2:25Should I post my updated .htaccess file and show you how it looks?–ChristianDec 23, 2012 at 2:35I just posted my htaccess file in my question. www.kgstiles.com/pureplantessentials.html still redirects to www.kgstiles.com/pureplantessentials/–ChristianDec 23, 2012 at 2:371I'm not sure if it was a mistake by you or if something I did was contrary to what I said above, but by changing RewriteCond %{REQUEST_URI} !^/pureplantessentials\.html$ to RewriteCond %{REQUEST_URI} !^pureplantessentials\.html$ (without the first /), I was able to make this work.–ChristianJan 16, 2013 at 4:58|Show3more comments | I have been here:How to exclude a specific file in htaccessand here:exclude files from rewrite rule in .htaccessbut neither worked. What might I be doing wrong?.htaccess file:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-content(/.*|)$ - [L] # don't take any action
RewriteRule ^wp-admin(/.*|)$ - [L] # don't take any action
RewriteRule ^wp-includes(/.*|)$ - [L] # don't take any action
RewriteCond %{REQUEST_URI} !^/pureplantessentials\.html$
RewriteRule ^moreinfo/(.*)$ http://www.kgstiles.com/moreinfo$1 [R=301]
RewriteRule ^healthsolutions/(.*)$ http://www.kgstiles.com/healthsolutions$1 [R=301]
RewriteRule ^(.*)\.html$ $1/ [R=301]
RewriteRule ^(.*)\.htm$ $1/ [R=301]
</IfModule> | How to exclude a specific file from a rewriterule |
Use the DirectoryIndex directive in your .htaccess fileDirectoryIndex index.phpShareFollowansweredDec 21, 2011 at 18:23Ulrich PalhaUlrich Palha9,43933 gold badges2626 silver badges3131 bronze badgesAdd a comment| | I am currently setting up a website from a client on his hosting account. The website address and for some reason doesn't default to .php files (that is: index.php). If I put index.php and there is no index.html file I receive the following error:If you feel you have reached this page in error, please contact the
web site owner:[email protected]If you are the web site owner,
it is possible you have reached this page because: The IP address has
changed. There has been a server misconfiguration. The site may have
been moved to a different server. If you are the owner of this website
and were not expecting to see this page, please contact your hosting
provider.His hosting is a shared hosting on cpanel. | How to set the default website page through htaccess? |
The cleanest way to do this without having to change any rules is to add a separate rule, before all others, that effectively disables rewriting for files in the directory, like this:RewriteRule ^\.well-known/.+ - [END]You may wish to add a file existence check immediately before the rule so your custom error response page is shown rather than the server's default:RewriteCond %{REQUEST_FILENAME} -fShareFolloweditedJan 13, 2021 at 2:47answeredOct 25, 2016 at 2:25WalfWalf8,91233 gold badges4444 silver badges6060 bronze badges22The RewriteRule ^\.well-known/.+ - [END] is the only thing that worked for me and I've tried many options!–Aleksandar PavićMay 14, 2019 at 10:363On an Apache 2.4 vhost without a document root, I had to add a slash after the^:RewriteRule ^/\.well-known/.+ - [END]–cweiskeMar 23, 2020 at 20:15Add a comment| | This is my current htaccess configuration of /frontend/webRewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME} [R,L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.phpI am trying to insert this:RewriteCond %{REQUEST_URI} !^.well-known/acme-challenge/$orRewriteCond %{REQUEST_URI} ! /\.well-known|^\.well-knownaboveRewriteRule ^.*$ https://%{SERVER_NAME} [R,L]to create letsecnrypt certificate, but none of this is working.Letsencrypt command to create certificate (debug coz Centos6):./letsencrypt-auto --debug certonly --webroot -w /var/www/html/example.com/frontend/web/ --email[email protected]--domains example.comletsencrypt error:The following errors were reported by the server:
Domain: example.com
Type: unauthorized
Detail: Invalid response from
http://example.com/.well-known/acme-challenge/%acme%Link above leads me to the HTTPS version of the site protocol. If I remove a redirect to https, I get a message on the successful receipt of the certificate . conclusion : .well-known continues to be sent to the https , my settings did not work , what am I doing wrong? | Letsencrypt with htaccess |
Off-hand, I believe you can use a context to do that:$context = stream_context_create(array (
'http' => array (
'header' => 'Authorization: Basic ' . base64_encode("$username:$password")
)
));
$data = file_get_contents($url, false, $context);ShareFolloweditedFeb 25, 2014 at 12:18answeredFeb 25, 2014 at 1:57bishopbishop38.6k1212 gold badges109109 silver badges142142 bronze badges1According to comment bychris dot vigelius at gmx dot netin PHP documentation (php.net/manual/en/function.stream-context-create.php) theheaderparameter MUST be an array (bug =bugs.php.net/bug.php?id=41051).–Jose Manuel Abarca RodríguezJan 19, 2022 at 20:26Add a comment| | This question already has answers here:Making a HTTP GET request with HTTP-Basic authentication(4 answers)Closed10 years ago.I need to reach a foreign .php page protected by a regular .htaccess file (Auth type Basic, htpasswords etc...).I'd like to send the user and password needed through the request. Is it possible? I would like to avoidcURLand allpecl_httpdependent functions if possible... | using file_get_contents to authenticate and access an htaccess protected file [duplicate] |
I know this is an old question now, but I've run into this problem, too.In the current version of Notepad++ (v5.9) the NppFTP plug-in (v0.23) has a setting for each connection called "LIST parameters". It is accessible viaSettings/Profile settings/FTP Misc. Enter "-al" there and hidden files should be visible. Remember to set it for each profile.ShareFolloweditedFeb 15, 2016 at 15:17Mosh Feu28.7k1616 gold badges9191 silver badges136136 bronze badgesansweredApr 16, 2011 at 19:53gkerenyigkerenyi51644 silver badges77 bronze badges17And remember to disconnect and connect again in order to function–machineaddictOct 2, 2013 at 8:54Add a comment| | I am working with Notepad and the FTP plugin. The .htaccess files do not show up in the folder tree of the server. Anyone else encountered this and know of a fix? | .htaccess in Notepad ++ |
This is possible using[NE] flag(noescape).By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.More infohttp://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_neShareFolloweditedJan 27, 2013 at 16:46Lefteris3,25655 gold badges3131 silver badges5353 bronze badgesansweredNov 24, 2010 at 13:17credendiocredendio28133 silver badges44 bronze badgesAdd a comment| | I have a situation where I want to take the following URL:/1/johnand have it redirect using Apache's htaccess file to go to/page.php?id=1&name=john#johnso that it goes to an html anchor with the name of john.I've found a lot of reference to escaping special characters, and to adding the [NE] flag so that the redirect ignores the # sign, but these don't work. For example, adding [NE,R] means that the URL just appears in the browser address as the original:http://example.com/page.php?id=1&name=john#john. | How to use htaccess to rewrite url to html anchor tag (#) |
For htaccessRewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !project/public/
RewriteRule (.*) /project/public/$1 [L]Put it into your public_html/ or www/ folder where is the root of example.com/ShareFollowansweredApr 23, 2015 at 16:44Germanaz0Germanaz091488 silver badges1818 bronze badges21Somehow this doesn't work with localhost as URL. (The 3rd line is the issue I believe, not sure why)–BenDec 14, 2015 at 22:12As @BenFransen said above this didn't work for me in localhost. Just changed to the dev linux machine hostname and it's working fine now.–cdsaenzOct 11, 2020 at 3:06Add a comment| | I have this structure:My domain: www.example.comand this is my laravel's project folder:http://www.example.com/projectand I would like to redirect tohttp://www.example.com/project/publicI know this answer has been answered before but I try to implement it and not work for me.Sorry for my english, I just speak spanish | How to redirect to public folder on laravel |
Lawrence Cherone - Thank you, that one works like a charm! Now it works:RewriteCond %{HTTP_HOST} ^www\.site1\.com [NC]
RewriteRule ^(.*)$ index.php?lang=it [NC,QSA]
RewriteCond %{HTTP_HOST} ^www\.site2\.com [NC]
RewriteRule ^(.*)$ index.php?lang=en [NC,QSA]Of course I check the www redirect before this rule.Thank you!!ShareFollowansweredApr 20, 2012 at 7:09tobia.zanarellatobia.zanarella1,26611 gold badge1717 silver badges2525 bronze badgesAdd a comment| | I have two different domains (let's say www.site1.com and www.site2.com) that point to the same hosting server.I need the two different domain names because I want to use the first one for the italian contents and the second one for the english contents. The contents are the same, unless for the language, but the domainshaveto be different.So, I'd like to write a rule that lets me translate from:www.site1.comto/?lang=itwww.site2.comto/?lang=enI usually use the same domain name for many different languages rewriting fromwww.site.com/it/to/?lang=it(of course, a transparent rewriting - the user doesn't see any different URL).I'd like to achieve the same using different domains but I can't figure out how... I've been working on it for hours and I can't achieve what I want!Usually I use this:RewriteCond %{REQUEST_URI} /([a-z]{2})
RewriteRule ^([a-z]{2})[/]*$ /index.php?lang=$1 [NC,QSA]I can't get this one work, to use different domains:RewriteCond %{HTTP_HOST} ^www.site1\.com [NC]
RewriteCond %{REQUEST_URI} !^/index.php?lang=it
RewriteRule ^(.*)$ /index.php?lang=it [NC,QSA]
RewriteCond %{HTTP_HOST} ^www.site2\.com [NC]
RewriteCond %{REQUEST_URI} !^/index.php?lang=en
RewriteRule ^(.*)$ /index.php?lang=en [NC,QSA] | htaccess rewrite based on hostname or domain name |
You can use theREMOTE_ADDRvariable in a RewriteCondRewriteCond %{REMOTE_ADDR} !^10\.0\.1\.1$
RewriteRule ^ /maintenance.htmlJust change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.ShareFolloweditedJul 2, 2009 at 12:31answeredJul 2, 2009 at 11:38Vinko Vrsalovic♦Vinko Vrsalovic335k5454 gold badges336336 silver badges374374 bronze badges1Don’t forget to mark the start and end in your regular expression.–GumboJul 2, 2009 at 11:42Add a comment| | I'd like to implement mod_rewrite to put my site into maintenance. Basically all IP addresses except a handful we specify would be forwarded to a static html page.Please can someone help with this rule. Also is there a way to turn this on and off easily without editing the htaccess file? | mod_rewrite based on ip |
Sounds like an IPv6 issue. When you're connecting to the site with 127.0.0.1, Apache sees the request as coming from the IPv4 localhost (127.0.0.1). But, when connecting to localhost, Apache sees the request as coming from the IPv6 localhost (::1).If this is the problem, you should be able to solve it by replacing theAllow from localhostline with aAllow from ::1line.ShareFollowansweredMay 14, 2011 at 22:42John FlatnessJohn Flatness32.9k55 gold badges7979 silver badges8181 bronze badges21What an absolute hero! I came across something similar to this but I put it down as localhost::1 not a separate line. Thanks for putting it straight!–amctavishMay 14, 2011 at 22:461Thanks for clearing that up! However, to any human being, "localhost", "127.0.0.1" and "::1" are mere aliases. Does Apache not make it easier to identify these aliases? Oh, and btw, could you add some info on how this works withRequirein Apache 2.4+?–DomiNov 2, 2014 at 11:33Add a comment| | I'm attempting to password protect my public folder so that anyone trying to access externally is prompted to enter a password but not locally. So far I have got it to work using 127.0.0.1 but not localhost. Obviously I COULD just used the ip address but it's more the fact I want to know why it doesn't work. I don't like to be defeated!#Enable Password Protection
AuthName "Password Protected Server"
AuthType Basic
AuthUserFile c:\xampp\apache\security\.htpasswd
Require valid-user
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Satisfy AnyMy code so far is an accumulation of:http://www.groovypost.com/howto/how-to/htaccess-password-protect-apache-website-security/htaccess password protect but not on localhostI'm running XAMPP 1.7.3 on Windows 7, in case that helps.Any assistance would be greatly appreciated! | .htaccess password protection allows 127.0.0.1 but not localhost |
Is it possible to use .htaccess to redirect all requests
for a particular folder on www.example.com to a folder on
static.example.com instead?Possible, but counter productive — the client would have to make an HTTP request, get the redirect response, then make another HTTP request.This costs a lot more than the single line of cookie data saved!Would this method also fool the CMS into thinking the images
were located in the default locations on its own domain?No.ShareFollowansweredSep 16, 2009 at 13:57QuentinQuentin929k129129 gold badges1.2k1.2k silver badges1.4k1.4k bronze badgesAdd a comment| | One of YSlow's measurables is to use cookie-free domains to serve static files."When the browser requests a static
image and sends cookies with the
request, the server ignores the
cookies. These cookies are unnecessary
network traffic. To workaround this
problem, make sure that static
components are requested with
cookie-free requestsby creating a
subdomain and hosting them there." --
Yahoo YSlowI interpret this to mean that I could experience performance gains if I movewww.example.com/imagestostatic.example.com/images.Although this is easy to do, I would lose the handy ability within my content management system (Joomla/WordPress) to easily reference and link to these images.Is it possible to use .htaccess to redirect all requests for a particular folder onwww.example.comto a folder onstatic.example.cominstead? Would this method also fool the CMS into thinking the images were located in the default locations on its own domain? | .htaccess, YSlow, and "Use cookie-free domains" |
Now I got a solution,
I updated my htaccess file.--RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^myhost\.com$ [NC]
RewriteRule ^ https://www.myhost.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ myhost.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]Now, It worked for me smoothly.. :)ShareFolloweditedJan 4, 2016 at 9:09user4419336answeredJan 4, 2016 at 8:27asiya khanasiya khan31111 gold badge22 silver badges88 bronze badges1firt time if i access link with http so does not work when i refresh page then it,s convert to https why in first access it,s not convert to https directly–abubakkar tahirAug 7, 2020 at 5:55Add a comment| | Point #1If I type:www.myurl.com/somepage
http://www.myurl.com/somepage
http://myurl.com/somepage
https://myurl.com/somepagehave it redirect tohttps://www.myurl.com/somepagePoint #2When I type in something like www.myurl.com it is redirecting to https://www.myurl.com/index.php.
Make it so the index.php is not displaying. It should just display https://www.myurl.comFrom Comment htaccessRewriteEngine On
RewriteCond %{HTTP_HOST} ^myhost\.com$ [NC]
RewriteRule ^(.*)$ myhost.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ myhost.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] | How to redirect http to https in codeigniter |
find / -name ".htaccess" -printReplace/with the root folder you like to start searching, in case you don't want to search the whole file system.Wikipedia has an article aboutfind, which also links to its man page.ShareFolloweditedNov 15, 2009 at 22:16answeredNov 15, 2009 at 22:09bluebrotherbluebrother8,71611 gold badge2121 silver badges2222 bronze badges1Note that, if you start from the root directory / , you'll need to run the find command with root privileges so that you're able to read all subdirectories on the system.–gareth_bowlesNov 16, 2009 at 16:18Add a comment| | Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.Closed8 years ago.Improve this questionI'm looking for a Linux command to go through all the directories on my server and find all .htaccess files. The output would be a list of all those files with full path, creation/modification date and filesize. | Find all htaccess files on server [closed] |
If I'm understanding correctly, the following should workRewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]This will redirect all requests that do not begin with/public/to URL that does.Hope that helps.ShareFollowansweredApr 26, 2011 at 15:13clmarquartclmarquart4,71111 gold badge2727 silver badges2424 bronze badges2Thanks, @clmarquart! What if we need to keep/example.com/to go to/example.com/index.htmlor/example.com/index.php?–moeyNov 14, 2011 at 16:12It can also be advantageous to add RewriteBase / before your RewriteCond. Especially if you are using VirtualDocumentRoot directives.–zmontecaMar 28, 2013 at 17:51Add a comment| | I've got a shared hosting account associated with a domain name and the root folder (correct me if that's the wrong term) is set to/so that all files on the server are public / accessible through the browser.Can I use .htaccess or something to change the root folder to something like/example.com/public/? | Changing the root folder via .htaccess |
OK. After a bunch of trial and error I answered my own question.The third line denotes that there has to be something in the URI in order to perform the redirect thus not redirecting if the url just contains the initial slash.RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} (.*)$
RewriteRule ^(.+)/$ http://www.domain.com/$1 [R=301,L]ShareFollowansweredNov 18, 2010 at 16:56DanDan1,46033 gold badges1212 silver badges1818 bronze badges25Instead ofhttp://www.domain.com/$1you can usehttp://www.%{HTTP_HOST}/$1better. So user don't need to edit that line and make possible errors.–Code GuruSep 25, 2013 at 7:412@YH's solution does not work for websites in subdirectories (nor for localhost, which cannot havewww.before itself). So e.g.localhost/web1/page1/is redirected in a wrong way towww.localhost/page1.–Martin PeckaNov 17, 2013 at 16:32Add a comment| | I've successfully modified my .htaccess file to remove trailing slashes on most pages but I'm wondering how to exempt my home page/directory? For example:domain.com/test/ successfully redirects to domain.com/testHOWEVER, when I hit my domain it will append the root documentdomain.com/ redirects to domain.com/index.phpIs there a condition that I can add to ignore root url trailing slash so that it doesn't attempt to remove the trailing slash and add my default script? Here's what I have so far:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L] | Remove trailing slash using .htaccess except for home / landing page |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.