这似乎是一个重复的问题,但我已经查看了所有类似的问题,似乎没有解决我的问题。我对php很新,我最近通过编辑.htaccess文件向我的网站发出了所有请求,如果用户输入localhost/questions/mcq.php?course_id=31
索引文件,然后从view/questions/mcq.php
导入,则通过index.php文件。然后我尝试使用.htaccess用这行重写url
RewriteRule ^questions/mcq/([0-9]+)$ /view/questions/mcq.php?course_id=$1 [NC]
我也试过
RewriteRule ^questions/mcq/([0-9]+)$ /questions/mcq.php?course_id=$1 [NC]
当我输入localhost/questions/mcq/31
时,我收到此错误
Warning: require_once(C:/xampp/htdocs/view/questions/mcq/31): failed to open stream: No such file or directory in C:\xampp\htdocs\resources\library\classes\template-class.php on line 25
Fatal error: require_once(): Failed opening required 'C:/xampp/htdocs/view/questions/mcq/31' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\resources\library\classes\template-class.php on line 25
我想知道我做错了什么,非常感谢任何帮助。
(编辑) 这是完整的.htaccess代码
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpeg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !.*\.js$ [NC]
RewriteRule ^(.*)$ /index.php?route=/$1 [QSA,L]
# RewriteRule ^questions/mcq/([0-9]+)?$ /view/questions/mcq.php?course_id=$1 [NC, L]
RewriteRule ^questions/mcq/([0-9]+)$ /view/questions/mcq.php?course_id=$1 [R=301, L]
答案 0 :(得分:0)
试试这个
RewriteRule ^questions/mcq/([0-9]+)$ /view/questions/mcq.php?course_id=$1 [R=301,L]
修改强>
试试这段代码
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpeg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !.*\.js$ [NC]
RewriteBase /
RewriteRule ^questions/mcq/([0-9]+)$ /view/questions/mcq.php?course_id=$1 [NC,END]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?route=$1 [QSA,L]