.htaccess 使用nice url重写子文件夹

.htaccess 使用nice url重写子文件夹,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,当我转到http://www.example.com/youtube/detail/abvcde在我的浏览器中,我想在内部将url重写为http://www.example.com/youtube/detail.php?id=abvcde。我尝试使用以下.htaccess执行此操作,但它给出了404错误 当前我的.htaccess如下所示: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FIL

当我转到
http://www.example.com/youtube/detail/abvcde
在我的浏览器中,我想在内部将url重写为
http://www.example.com/youtube/detail.php?id=abvcde
。我尝试使用以下.htaccess执行此操作,但它给出了404错误

当前我的.htaccess如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

将以下代码放入服务器根目录中的htaccess文件中:

RewriteEngine On
RewriteRule ^youtube/detail/(.+)$ youtube/detail.php?id=$1 [L]

您可以将此代码放入您的
/youtube/.htaccess

Options -MultiViews

RewriteEngine On
RewriteBase /youtube/

RewriteRule ^detail/([^/]+)$ detail.php?id=$1 [L]

“它不起作用”是什么意思?请添加更多详细信息。在编写问题时,请确保始终包含清晰的问题陈述。“它不起作用”是一种轻描淡写的说法。如果你的代码运行得非常好,你就不会来这里了。相反,关注你所看到的:你是否出错,你的电脑是否着火,紫色独角兽是否在你的屏幕上游荡。根据你的代码,我假设你得到一个404错误,但如果不是这样,请编辑你的问题。