duanpo2813 2014-07-22 04:01
浏览 21

检查URL重写代码

I've been working on this URL rewriting .htaccess code but some people have said that I am doing it wrong or backwards:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php\?(.*)p=(?!admin)(?!superadmin)((?![^&]*?edit)[^\s&]+) [NC]
RewriteCond %{THE_REQUEST} /index\.php\?(.*)p=([^&\ ]+)&?([^\   ]*) [NC]
RewriteRule ^ /%2?%1%3 [R=301,L]

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

Ultimately I want the user not to see the links with query strings but I need the query strings to still exist and be usable somehow so that I can check for values of $_GET variables.

In other words I need this: - domain.com/index.php?p=Home to be rewritten as domain.com/Home - domain.com/index.php?p=Bio to be rewritten as domain.com/Bio - when a user clicks a link from the home page that points to domain.com/index.php?p=Bio they should see domain.com/Bio in the browser's url bar but I should still be able to echo $_GET['p'] and get 'Bio' when I land on the Bio page.

Make sense?

Thanks for your help in advance!

  • 写回答

1条回答 默认 最新

  • doumo3903 2014-07-22 04:26
    关注

    Small tweaks, and it should work.

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} index\.php\?.*(?<!\w)p=(?![^&]*(?:admin|edit))([^\s&#]+) [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/?$ index.php?p=%1 [L,QSA]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?