问题描述
我正在尝试为我的网站创建一个网址缩短,任何对 example.com/u/*
的请求都应重写为 {{1} } !
请注意:example.com/cpp-cgi-test.cgi?*
目录不存在,我将其添加到 URL 只是为了美化短链接!
我在使用 Cpanel 的云托管提供商环境中;不是服务器!
public_html 下 /u
的内容:
.htaccess
我只添加了前三行!
问题是:
当我尝试访问 Options +FollowSymLinks
RewriteEngine On
RewriteRule "^/u/(.*)" "/cpp-cgi-test.cgi?$1" [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 @R_460_4045@ion,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
仍然我不打算 index.html:
example.com/cpp-cgi-test.cgi
解决方法
根据您显示的示例,您能否尝试遵循 .htaccess 文件中的规则,考虑到从 u|U
开始的任何 URI 都应该通过查询重新写入后端的 cpp-cgi-test.cgi
文件传递给它的字符串。另外,请确保在测试 URL 之前清除浏览器缓存。
RewriteEngine ON
RewriteRule ^u/(.*)/?$ cpp-cgi-test.cgi?$1 [NC,L]