我正在使用Codeigniter和WordPress创建网站。
Codeigniter安装在根目录上。 WordPress,用于根目录内子域目录中的博客。
这是目录结构。
var / www / html / codeigniter-此处为根网站
/ var / www / html / codeigniter / blog-WordPress博客的子域
这是根目录(.var / www / html / codeigniter)的.htacess文件
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
这是博客目录(/ var / www / html / codeigniter / blog)的.htaccess文件
/* SINGLETON DESIGN PATTERN (slides and https://sourcemaking.com/design_patterns/singleton)
* INTENT
- Ensure a class has only one instance, and provide a global point of access to it.
- Encapsulated "just-in-time initialization" or "initialization on first use".
* ABOUT
- Make the class of the single instance object responsible for creation, initialization,
access, and enforcement.
*/
namespace SpaceTaxi_3.States.GameRunning.Parser {
public partial class LevelParser {
private static LevelParser instance;
public static LevelParser GetInstance() {
return LevelParser.instance ?? (LevelParser.instance = new LevelParser());
}
public Dictionary<char, string> Obstacles;
public Dictionary<char, string> Platforms;
public Dictionary<char, string> Exits;
public Dictionary<string, Tuple<int, char, string, int, int, Entity>> Costumer;
public List<Entity> ObstacleEntities { get; set; }
public List<Platform> PlatformEntities { get; set; }
public List<Entity> ExitEntities { get; set; }
public string[] LevelFile;
// Wrapper
public void Load(string fileName) {
// Catches incorrect files here
if (ValidMapCheck(fileName)) {
PlatformEntities = new List<Platform>();
ExitEntities = new List<Entity>();
ObstacleEntities = new List<Entity>();
Platforms = new Dictionary<char, string>();
Exits = new Dictionary<char, string>();
Obstacles = new Dictionary<char, string>();
Costumer = new Dictionary<string, Tuple<int, char, string, int, int, Entity>>();
LevelFile = ReadFile("Levels", fileName);
Platforms = GetPlatforms(LevelFile);
Exits = GetExits(LevelFile);
Obstacles = GetObstacles(LevelFile);
Costumer = GetCustomerInfo(LevelFile);
AddEntities(GetAllTiles(LevelFile));
}
}
/// <summary>
/// Checks whether a file exists or not
/// </summary>
private void ValidatePath(string file) {
if (!File.Exists(file)) {
throw new FileNotFoundException($"Error: " +
$"The path to \"{file}\" does not exist.");
}
}
/// <summary>
/// Finds full path to directory (e.g. directoryName: "Levels" or "Assets")
/// Starts from /bin/Debug folder, then goes to parent /bin, and so on.
/// Casts an exception if we iterated down to the root of the tree.
/// </summary>
private string GetPath(string directoryName) {
DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.
GetExecutingAssembly().Location));
while (dir.Name != directoryName) {
if (dir.FullName == dir.Root.Name) {
throw new FileNotFoundException(
$"Error: Directory \"{directoryName}\" does not exist.");
} else {
foreach (var i in dir.GetDirectories()) {
if (i.Name == directoryName) {
return i.FullName;
}
}
dir = dir.Parent;
}
}
return dir.FullName;
}
/// <summary>
/// Making sure our mapfiles are not tampered with by calculating the checksum
/// Source: https://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file
/// Source: https://en.wikipedia.org/wiki/MD5
/// </summary>
/// <param name="filename"></param>
public string CheckMD5(string filename)
{
// "using": automatically disposes the object after use,
// even if exception is casted
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
/// <summary>
/// Checks for invalid files and invalid filecontent
/// </summary>
public bool ValidMapCheck(string filename) {
var hash = "";
var hash32bit = "";
Console.WriteLine("Hash: " + CheckMD5(Path.Combine(GetPath("Levels"), filename)));
// Checks for invalid files
if (filename != "the-beach.txt" && filename != "short-n-sweet.txt") {
throw new ArgumentException($"Parser cannot load: {filename}");
}
// Checks for invalid file content
if (filename == "the-beach.txt") {
hash = "81b89b1908e3b3b7fcd7526810c32f14";
hash32bit = "34d0e9c5ea54bfc60a0365f28b7d3a19";
}
if (filename == "short-n-sweet.txt") {
hash = "e97f28bfff174f9643c088814377ada6";
hash32bit = "5c4832a9a5510bdab5976ad0e6905e85";
}
var checksum = CheckMD5(Path.Combine(GetPath("Levels"), filename));
if (checksum == hash || checksum == hash32bit) {
return true;
}
throw new ArgumentException($"You've tampered with {filename}!");
// Todo: Find out how to hide these hash strings and to avoid inline hardcode
}
/// <summary>
/// Collects a string[] containing all strings in the file
/// </summary>
private string[] ReadFile(string directoryName, string fileName) {
var dir = GetPath(directoryName);
string path = Path.Combine(dir, fileName);
ValidatePath(path);
return File.ReadAllLines(path);
}
/// <summary>
/// Extracts ASCII characters from the txt file and appends it
/// to an array. Later we will use this array to draw pictures.
/// </summary>
private List<char> GetAllTiles(string[] txtFile) {
var charList = new List<char>();
for (int i = 0; i < 23; i++) {
foreach (var j in txtFile[i]) {
charList.Add(j);
}
}
return charList;
}
/// <summary>
/// Adds all objects to the appropriate map being loaded
/// We iterate from top-left (0,1) of the screen to bottom-right (1,0)
/// </summary>
private void AddEntities(List<char> map) {
float tmpX = Constants.X_MIN;
float tmpY = Constants.Y_MAX;
int index = 0;
// Going from top (y 1.0) to bottom (y 0.0)
while (tmpY > Constants.Y_MIN) {
// Going from left (x 0.0) to right (x 1.0)
while (tmpX < Constants.X_MAX) {
// There can be empty strings in our list of strings.
if (map[index].ToString() == " ") {
index += 1;
} else {
// Adds obstacles
if (Obstacles.ContainsKey(map[index])) {
var shape = new StationaryShape(new Vec2F(tmpX, tmpY),
new Vec2F(Constants.WIDTH, Constants.HEIGHT));
var file = Path.Combine(GetPath("Assets"),
"Images", Obstacles[map[index]]);
ValidatePath(file);
ObstacleEntities.Add(new Entity(shape, new Image(file)));
}
// Adds platforms
if (Platforms.ContainsKey(map[index])) {
var shape = new StationaryShape(new Vec2F(tmpX, tmpY),
new Vec2F(Constants.WIDTH, Constants.HEIGHT));
var file = Path.Combine(GetPath("Assets"), "Images",
Platforms[map[index]]);
ValidatePath(file);
PlatformEntities.Add(new Platform(shape, new Image(file), map[index]));
}
// Adds exits
if (Exits.ContainsKey(map[index])) {
var shape = new StationaryShape(new Vec2F(tmpX, tmpY),
new Vec2F(Constants.WIDTH, Constants.HEIGHT));
var file = Path.Combine(GetPath("Assets"), "Images",
Exits[map[index]]);
ValidatePath(file);
ExitEntities.Add(new Entity(shape, new Image(file)));
}
// Update index
index += 1;
}
tmpX += Constants.WIDTH;
}
tmpX = 0;
tmpY -= Constants.HEIGHT;
}
}
}
}
答案 0 :(得分:0)
您尝试访问的子域必须在application / config / routes中具有与其关联的路由,并且应该指向一个有效的控制器函数,该函数返回有效的HTML / JSON数据
答案 1 :(得分:0)
正在工作。我不小心将博客目录放入另一个目录。现在可以将博客移至子域目录。