dongshou6041 2014-12-03 01:00
浏览 53

如何进行目录重定向

I've seen websites have profile pages do things like 'http://www.example.com/myusername/ show the the person with the username 'myusername's' profile. I was wondering how to do this?

I've seen examples on how to do this with htaccess but it does a full redirect, not allowing post data, get data, etc. How could I do this?

  • 写回答

2条回答 默认 最新

  • douhanshu5517 2014-12-03 01:09
    关注

    Use .htaccess's mod_rewrite option to create rewrites that will maintain the query string and/or posted data. A quick example (taken from CodeIgniter) :

    RewriteEngine on
    RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    This will mean that all requests go to index.php and your index.php script would be setup to parse this URL into a proper class and/or function. This allows for a single entry point that can be managed by a system. This is used by all major systems, from Wordpress to Magento to Laravel 4 to CodeIgniter.

    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线