使用 .htaccess 重定向到目录 URL,但显示该 URL 就像在根目录中一样
我目前有一个具有以下文件结构的 CRUD:
index.php 文件重定向到 add-product.php, delete.php 和其他文件。问题是,URL 看起来像:myapp.com/resources/views/add-product,但我希望它看起来像 myapp.com/add-product。我发现其他 StackOverflow 帖子与此类似,但它重定向到所需的链接,而不是重定向到正确的链接但显示所需的链接,因此该网站无法正常工作(“在此找不到所请求的 URL”)服务器”)。 .htaccess 文件如下所示:
Options +FollowSymLinks +MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^resources/(.*)$ /$1 [L,NC,R]
我还使用该文件从 URL 中删除 .php。最后一行是处理错误重定向的行。我该怎么办?感谢您抽出时间。
I currently have a CRUD that has the following file structure:
The index.php file redirects to the add-product.php, delete.php and other files. The problem is, the URL looks like: myapp.com/resources/views/add-product but I want it to look like myapp.com/add-product. I found other StackOverflow posts similar to this, but it redirects to the desired link, instead of redirecting to the correct link but showing the desired one, and because of that the site doesn't work ("The requested URL was not found on this server"). The .htaccess file looks like this:
Options +FollowSymLinks +MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^resources/(.*)$ /$1 [L,NC,R]
I'm also using the file to be able to remove the .php from the URLs. The last line is the one handling the wrong redirection. How can I go about this? Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样使用它:
一旦确认它工作正常,请将
R=302
替换为R=301
。测试mod_rewrite
规则时避免使用R=301
(永久重定向)。You may use it like this:
Once you verify it is working fine, replace
R=302
toR=301
. Avoid usingR=301
(Permanent Redirect) while testing yourmod_rewrite
rules.