扩展后删除不需要的字符

时间:2016-03-24 03:00:54

标签: .htaccess

我的页面是通过cgi中的查询调用的。

xyz.cgi?page=abc.html

我遇到的问题是我得到了针对确实存在的页面的机器人请求,但请求在.html后面有字符,结果是404.

.htaccess扩展后.html是否有办法剥离所有内容?

1 个答案:

答案 0 :(得分:1)

您可以使用以下规则删除html扩展名后的字符:

emp->firstName = lineList[2]

这将重定向

#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
#include "baselibrary.h"
struct Employee
{
    int16_t id; // Employee ID
    std::string lastName; // Employee's last name
    std::string firstName; // Employee's first name
    char middleInitial; // Employee's middle initial
    int16_t age;
    bool gender; // false is male, true is female
    float salary;
    int16_t experience; // # of years working at company
    int16_t department; // Department from Departments::
};
std::vector<Employee> employeeArrayN;
int empNumN{1};
//... tons of snipped out code ...//
bool loadFromDatabaseFileN(){
    std::string filename;
    std::cout << "Please enter filename to load (with extension): ";
    std::getline(std::cin, filename);
    std::ifstream file(filename);
    std::cout << "Breakpoint 0!";
    if (!file){
        std::cout << "Error in opening file. ";
        return false;
    }
    std::cout << "Breakpoint 1!";
    while (file) // ifstream returns 0 when reaching EOF - 0 is boolean false
    {
        // it's probably OK to ignore the code under here, but you never know...
        std::string lineInput;
        std::cout << "Breakpoint 2!";
        Employee *emp = new Employee;
        std::cout << "Breakpoint 3!";
        ++empNumN;
        std::cout << "Breakpoint 4!";
        std::getline(file, lineInput);
        std::vector<std::string> lineList = splitString(lineInput, ' ');
        int16_t tempId;
        std::cout << "Breakpoint 5!";
        std::stringstream(lineList[0]) >> tempId;
        emp->id = tempId;
        emp->lastName = lineList[1];
        emp->firstName = lineList[2];
        char tempMInit;
        std::stringstream(lineList[3]) >> tempMInit;
        emp->middleInitial = tempMInit;
        int16_t tempAge;
        std::stringstream(lineList[4]) >> tempAge;
        emp->age = tempAge;
        bool tempGend;
        std::stringstream(lineList[5]) >> tempGend;
        emp->gender =  tempGend;
        float tempSalary;
        std::stringstream(lineList[6]) >> tempSalary;
        emp->salary = tempSalary;
        int16_t tempExperience;
        std::stringstream(lineList[7]) >> tempExperience;
        emp->experience = tempExperience;
        int16_t tempDepartment;
        std::stringstream(lineList[8]) >> tempDepartment;
        emp->department = tempDepartment;
        employeeArrayN.resize(empNumN);
        employeeArrayN[empNumN - 1] = *emp;
        std::cout << "Added new employe: [ID " << emp->id << "] " << emp->lastName << ", " << emp->firstName << " " << emp->middleInitial << ". \n";
    }
    file.close();
    return true;
}
//...snip...//

//fix is a function I added just for this question, I wouldn't want to bother you with my monolithic actual function//
void fix()
{
    bool notGonnaUse = loadFromDatabaseFileN();
}

 RewriteRule ^(.+\.html).+$ /$1 [L,R]

/foo.htmlchars

编辑:

要将 /xyz.cgi?page=foo.htmlchars 重定向到 /xyz.cgi?page=foo.html ,您可以使用以下内容:

/foo.html