我尝试使用php和.htaccess文件启用/禁用站点维护模式。
我想找到一种方法来评论/取消注释.htaccess文件中# BEGIN/END MAINTENANCE MODE
与PHP之间的界限。
# BEGIN MAINTENANCE MODE
# <IfModule mod_rewrite.c>
# RewriteEngine on
# RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
# RewriteCond %{REQUEST_URI} !maintenance.html$ [NC]
# RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
# RewriteRule .* maintenance.html [R=302,L]
# </IfModule>
# END MAINTENANCE MODE
有什么想法吗?
答案 0 :(得分:1)
正如其他人在评论中提到的那样;您不希望PHP对您的htaccess文件具有写入权限。这可能是一种安全风险。
作为@arkascha mentioned,一种方法可以是检查import random
import sys
import time
print("Welcome to the weird sentence generator.")
wantto = True
print("Press enter to generate a weird sentence. Press Q to quit.")
while True:
senttype = random.randint(1,5)
VERBS = ["dying", "farting","eating","pooping","pooing","drinking","running","walking","dancing","singing","learning","burping","digesting","fighting","licking","flying","smoking","mating","reproducing","playing","thinking","peeing","typing","programming","sitting","standing","slipping","ice-skating","skating","riding","murdering","killing","snoring","watching","looking","sprinting","jogging","opening","closing","calling","drawing","painting","washing","cleaning","cooking","kissing","snogging","showering","bathing","lifting","listening","conjuring","writing","composing","socializing","talking","lip-syncing to music.ly","being annoying","wrestling","practicing martial art","meeting people","skateboarding","riding a bike","proposing to his girlfriend","trying to get good at Game of War because he kept getting rekt by TheLegend27","clicking stuff on his PC","clicking his tongue","whistling","clapping","helping someone kill themself","failing to think of examples for this random sentence program"]
verb = random.choice(VERBS)
VERBSTWO = ["die","fart","eat","poop","poo","drink","run","walk","dance","sing","learn","flirt","digest","fart","eat","fly","burp","dig","smoke","lick","snore","kiss","snog","vomit","throw up","play","think","pee","type","arrest","program","sit","stand","lie down","slip","ice-skate","skate","skateboard","ride","murder","kill","slaughter","snore","watch","look","sprint","jog","open","close","call","drag","draw","paint","photograph","wash","clean","cook","bathe","solve"]
NOUNS = ["pig","cow","chicken","camel","man","woman","girl","boy","mouse","house","box","computer","fox","omelette","egg","sandwich","mouse pad","remote control","TV remote","screen","frame","statue","painting","wall","floor","ceiling","window","table","chair","TV","xBox 360","Wii","Playstation 1","Playstation 2","Playstation 3","Playstation 4","xBox 1","Nintendo DS","Game Boy","Nintendo 3DS","charger","phone","telephone","iPhone","iPad","iPod","flower","tree","bush","president","prime minister","baby","mirror","cupboard","wardrobe","walrus","goat","koala","sea lion","fish","goldfish","DVD","DVD player","USB","bed","bedroom","toilet","bathroom","living room","room","kitchen","oven","fridge","freezer","gate","snake","python","document","sentence","windowsill","shower","dining room","napkin","fork","knife","spoon","sugar cube","sugar","salt","potato","carrot","cucumber","tomato","soup","vinegar","crisp","chip","French fry","egg","pillow","blanket","matress","sheet","file","user","rapper","singer","runner","builder","zombie","wizard","engineer","monkey","gorilla","baboon","skeleton","tiger","pop star"]
noun = random.choice(NOUNS)
ADVERBS = ["slowly","quickly","stupidly","cleverly","harshly","horribly","beautifully","skillfully","easily","difficultly","nicely","pleasantly","surprisingly","prettily","artfully","craftily","hungrily","thirstily","greedily","selfishly","unselfishly","kindly","generously","randomly","idiotically","periodically","logically","illogically","controversially","sickeningly","poorly"]
adverb = random.choice(ADVERBS)
ADJECTIVES = ["fat","thin","weird","strange","normal","average","random","legendary","horrible","vile","cruel","ugly","pretty","beautiful","disgusting","pleasant","surprising","nice","artful","pretty","crafty","hungry","thirsty","greedy","selfish","unselfish","kind","generous","thorough","idiotic","stupid","obese","logical","illogical","controversial","sickening","poor","dumb"]
adjective = random.choice(ADJECTIVES)
adjective2 = random.choice(ADJECTIVES)
noun2 = random.choice(NOUNS)
COLOURS = ["blue","green","maroon","yellow","pink","purple","white","black","brown","hazel","red","orange","turquoise","peach","tan","chestnut","chocolate"]
colour = random.choice(COLOURS)
verb2 = random.choice(VERBSTWO)
what = input()
if senttype == 1:
print("The",noun,"was",adverb,verb,"in the",adjective,"park, but the", adjective2,colour,noun2,"wanted him to", verb2+".")
if senttype == 2:
print("My favourite",noun,"is the",adjective,colour,"one",adverb,verb,"in a",noun2+"!")
if senttype == 3:
print("I",verb2,"with a",adjective,noun,"frequently and",adverb+".")
if senttype == 4:
print("Although",verb,"is",adjective+", the",noun,"was too",adjective2,"to",verb2,"it.")
if senttype == 5:
print("The",adjective,colour,noun,"is good at",verb,"and likes to",adverb,verb2,"every day!")
if what =="Q" or what == "q":
sys.exit()
文件是否存在,并根据以下内容启用/禁用维护模式:
maintenance.html
然后,在PHP方面,确切地想要创建注释/取消注释逻辑的位置,您只需重命名Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{REQUEST_URI} !maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
# Check if the maintenance.html file exists,
# if so, redirect all requests to that file.
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteRule .* /maintenance.html [R=503,L]
</IfModule>
文件。像这样:
maintenance.html
再说一遍;使用503代码进行维护:
What is the correct HTTP status code to send when a site is down for maintenance?