【问题标题】:htaccess rewrite url to hide php question markhtaccess 重写 url 以隐藏 php 问号
【发布时间】:2013-12-24 16:24:48
【问题描述】:

我的 url 格式mysite/profile/?theusernamewith hide php extension,我试图在 url 中隐藏问号,所以 url 会像mysite/profile/theusername,查找了几篇关于我应该做的是添加外部重定向然后在 htaccess 中进行内部转发的帖子,尝试了很多代码仍然无法正常工作。这就是我现在拥有的:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /   

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

【问题讨论】:

  • 如果你忽略RewriteCond !{QUERY_STRING} idstackoverflow.com/questions/4881410/…,这里可以回答这个问题
  • @popnoodles 我认为这是用于将链接重定向到上层目录,例如 /foo/?bar 到 /foo

标签: php regex .htaccess mod-rewrite url-rewriting


【解决方案1】:

保持你的 .htaccess 像这样:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /profile/

# new rules
RewriteCond %{THE_REQUEST} \s/+profile/?(?:index\.php)?\?([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]

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

# php hiding
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

【讨论】:

  • 这个用于隐藏 php 扩展,但我的 url 仍然有问号,如 /profile/?theusername
  • :( URL变为:/ profile /////////////////////////,这可能是帮助,实际的URL:MySite / Profile /索引.php?theusername 与 htaccess 隐藏扩展名变为 /profile/?theusername
  • 你在这个.htaccess中还有其他规则吗?
  • 首先你写你的 URI 是:mysite/profile/?theusername 现在你说 URL 是 mysite/profile/index.php?theusername 确保提供正确的信息以获得最佳答案。
  • 对不起,我的网址是 mysite/profile/?theusername with htaccess,我只是告诉你文件结构。没什么不同。
猜你喜欢
  • 2013-08-13
  • 2016-10-03
  • 2016-02-28
  • 2013-09-03
  • 2021-08-21
  • 1970-01-01
  • 2012-05-30
  • 2013-06-08
  • 1970-01-01
相关资源
最近更新 更多