Url mod_重写以重定向到php文件
我想要:www.example.com/username 重定向到:www.example.com/user.php?id=username 尝试使用我找到的这个mod_重写规则:RewriteRule^user/([a-z]+)/?$user.php?id=$1 我对此做了很多研究,但仍然无法使其发挥作用。我开始觉得某个地方有冲突……我不知道。我迷路了Url mod_重写以重定向到php文件,url,mod-rewrite,redirect,profile,Url,Mod Rewrite,Redirect,Profile,我想要:www.example.com/username 重定向到:www.example.com/user.php?id=username 尝试使用我找到的这个mod_重写规则:RewriteRule^user/([a-z]+)/?$user.php?id=$1 我对此做了很多研究,但仍然无法使其发挥作用。我开始觉得某个地方有冲突……我不知道。我迷路了 <VirtualHost 111.111.111.111.:443> ServerAdmin webmaster@
<VirtualHost 111.111.111.111.:443>
ServerAdmin webmaster@localhost
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/public
<Directory /home/public>
Options -Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
RewriteEngine On
RewriteRule ^user/([a-z]+)/?$ user.php?id=$1
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
</VirtualHost>
服务器管理员webmaster@localhost
ServerName example.com
ServerAlias www.example.com
DocumentRoot/home/public
选项-索引跟随符号链接多视图
不允许超限
命令允许,拒绝
通融
重新启动发动机
重写规则^user/([a-z]+)/?$user.php?id=$1
ErrorLog/var/log/apache2/error.log
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别警告
CustomLog/var/log/apache2/access.log组合
重新启动发动机
重写cond%{REQUEST_METHOD}^(跟踪|跟踪)
重写规则。*-[F]
您可以使用.htaccess将404重定向到一个.php文件,该文件以与$\u GET类似的方式处理URI,而不是mod_rewrite$\u服务器['REQUEST\u URI']
和preg\u match()
应该会有帮助
RewriteEngine on
RewriteRule ^user/([^/\.]+)/?$ /user.php?id=$1 [L]
这将导致所有/user/username被重定向到user.php?id=username。然后,您可以签入您的PHP:
if (isset($_GET['user'])) {
// Check if the username exists.
// SELECT ... FROM users WHERE username = ..
}
重写规则^user/([^/\.]+)/?$/user.php?id=$1[L]同样的事情一直在发生。该网站目前的结构如下:www.example.com/user.php和www.example.com/user/user.php分别带有$GET['id']和$GET['id']进行测试。还是有404页。可能是我丢失的其他地方的服务器设置吗?