Apache RewriteRule 不适用

Apache RewriteRule doesn't apply

我正在尝试为我的站点创建一个 URL shortner,任何对 example.com/u/*[=51= 的请求] 应该改写为 example.com/cpp-cgi-test.cgi?* !

注意:目录/u不存在,我把它加到URL只是为了美化短link!

我在 Cpanel 的云托管提供商环境中;不是服务器!


public_html下.htaccess的内容:

Options +FollowSymLinks
RewriteEngine On
RewriteRule "^/u/(.*)" "/cpp-cgi-test.cgi?" [NC]

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors On
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 8M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php73"
   php_value upload_max_filesize 2M
   php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors On
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 8M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php73"
   php_value upload_max_filesize 2M
   php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php72___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

只有前三行是我加的!


问题是:

当我尝试访问 example.com/u/Abcde 时,它以 error 404!

此外,我尝试了下面的代码只是为了防止出现问题,因为 /u 目录不存在;但是当我输入 example.com/cpp-cgi-test.cgi 时使用此代码我仍然不会 index.html:

Options +FollowSymLinks
RewriteEngine On
RewriteRule "^/cpp-cgi-test.cgi" "https://example.com" [NC]

根据您显示的示例,考虑到任何从 u|U 开始的 URI 都应该在后端重写到 cpp-cgi-test.cgi 文件,请您尝试在您的 .htaccess 文件中遵循规则传递给它的查询字符串。另外,请确保在测试 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteRule ^u/(.*)/?$ cpp-cgi-test.cgi? [NC,L]