【发布时间】:2022-01-17 12:11:20
【问题描述】:
在过去的几个小时里,我似乎无法弄清楚为什么我的 .htaccess 文件会重定向到一个空白 url。下面是我的 htaccess 文件。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ /test/user-profile/%1? [R=301,L]
我正在尝试重写 www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4
它确实重写了 URL,但是页面显示“在此服务器上找不到请求的 URL”。 htaccess 文件位于public_html 文件夹中,因此我试图在www.exampleurl.com/test/userslist.php 中选择一个特定用户,该用户将转到www.exampleurl.com/test/user-profile.php。在使用 htaccess 之前,这一切都可以完美运行。 www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4 但它只是找不到网址或文件?我是下面的超级菜鸟文件夹路径-> public_html/test/userslist.php & user-profile.php
似乎无法弄清楚该怎么做。是的,我确实开启了 mod-rewrite。
【问题讨论】:
标签: .htaccess mod-rewrite