Laravel 4.1将来自www.mydomain.com的所有请求重定向到具有301永久重定向的mydomain.com

时间:2015-05-20 18:00:10

标签: php .htaccess redirect laravel-4

不是Laravel的重复,如何重定向为301和302:

我在Apache webserver上使用Laravel 4.1,php 5.4。我想重定向所有要求的请求

int main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pArgs,*pXVec,*c, *xarr1;
int i;
float fArray[5] = {0,1,2,3,4};
//float *p = &fArray[0] ;
npy_intp m = 5;
//void* PyArray_GetPtr(PyArrayObject* aobj, npy_intp* ind)¶


// Initialize the Python Interpreter
Py_Initialize();
PySys_SetArgv(argc, argv); 
// Build the name object
pName = PyString_FromString(argv[1]);

// Load the module object
pModule = PyImport_Import(pName);
printf("check0\n");
// pDict is a borrowed reference 
pDict = PyModule_GetDict(pModule);
printf("check1\n");
// pFunc is also a borrowed reference 
pFunc = PyDict_GetItemString(pDict, argv[2]);
printf("check2\n");
//    if (PyCallable_Check(pFunc)) 
//    {
// Prepare the argument list for the call
//xarr1 = PyFloat_FromDouble(xarr[1]);
    printf("check3\n");
c = PyArray_SimpleNewFromData(1,&m,NPY_FLOAT,(void *)fArray);
printf("check3\n");
    pArgs = PyTuple_New(1);
    PyTuple_SetItem(pArgs,0, c);    

    pValue = PyObject_CallObject(pFunc, pArgs);

    if (pArgs != NULL)
    {
        Py_DECREF(pArgs);
    }

//}
//   else 
//    {
//        PyErr_Print();
//    }

// Clean up
Py_DECREF(pModule);
Py_DECREF(pName);

// Finish the Python Interpreter
Py_Finalize();

return 0;
}

我正在计算我的规范网址,如下所示:

 http://www.example.com/whateva 
 to 
 http://example.com/whateva

如何进行重定向?

1 个答案:

答案 0 :(得分:1)

很抱歉打扰了你,但我现在找到了答案。

我在app/filter.php

中添加了以下代码
App::before(function($request){
   //Remove the 'www.' from all domains
   if (substr($request->header('host'), 0, 4) === 'www.') {
      $request->headers->set('host', 'example.com');
     return Redirect::to($request->path());
   }
 }); 

像魅力一样工作,没有别的事情要做。