dongli564510 2013-10-20 09:23
浏览 31
已采纳

RewriteRule问题 - 模块化PHP错误请求

What I'm ultimately looking to do is do /about instead of /main.php?p=about. I've seen a few posts (like this!) but none seem to work from me.

Firstly, I was putting the ReWrite rules in httpd.conf..is this correct? Lots of places mention .htaccess but I didn't have that file in any directory that seems important (the only references are in phpMyAdmin). I copied the file from phpMyAdmin into htdocs and then replaced the text with a simple rule:

RewriteEngine on
RewriteRule home main.php [L]

However localhost/home reported a Bad Request.

So firstly which file should I use & if .htaccess where should I put the file & do I have to reference it in any other files? Secondly, is the following likely to work for my desired approach?

RewriteEngine on
RewriteRule ^([^/]+)/?  main.php?p=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Thanks for any clarity & help. Mike

  • 写回答

1条回答 默认 最新

  • dqkx69935 2013-10-20 09:25
    关注

    You actually have conditions (RewriteCond) after RewriteRule. It should be other way round.

    Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ /main.php?p=$1 [L,QSA]
    
    RewriteRule ^home/?$ main.php [L,NC]
    

    Suggested Read: Apache mod_rewrite Introduction

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.