【问题标题】:How to change the url as Subfolder如何将网址更改为子文件夹
【发布时间】:2015-12-13 23:34:24
【问题描述】:

我的网址是:http://www.website.com/profile.php?username=xyz

但我想改成这样:http://www.website.com/xyz

可以使用.htaccess吗?

我试过了,但它给了我:

内部错误。

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ! -f
RewriteCond %{REQUEST_FILENAME} ! -d
RewriteRule (.*) profile.php?username=$1

【问题讨论】:

  • 你能显示你的规则吗(即使它不起作用)
  • RewriteBase 上的 RewriteEngine / RewriteCond %{REQUEST_FILENAME} ! -f RewriteCond %{REQUEST_FILENAME} ! -d RewriteRule (.*) profile.php?username=$1
  • 这段代码看起来不错。当您收到 500(内部服务器错误)时,您能否检查您的 Apache error.log 以查看确切的错误。
  • [2015 年 9 月 17 日星期四 13:07:15.016904] [core:alert] [pid 2944:tid 840] [client ::1:59761] D:/wamp/www/website/.htaccess : RewriteCond: bad flag delimiters, referer: localhost/website/profile.php?username=xyz

标签: php html .htaccess url-rewriting


【解决方案1】:

试试这个代码:

DirectoryIndex index.php
RewriteEngine on
RewriteBase /

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

!-f-dRewriteCond 之间不应有空格。

【讨论】:

  • 您好,谢谢您的回复,它正在工作但是现在任何网址都在打开页面。 website.com/xyz, website.com/123abc....i 认为这是如何实现的?
  • 是的,没错。它会将http://www.website.com/foobar 之类的任何内容路由到http://www.website.com/profile.php?username=foobar 只有您在profile.php 中的代码才能通过可能查询数据库来确定用户名是否有效。
  • 是的,它解决了我的问题,您为我提供了极好的帮助。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多