简体   繁体   English

如何在 .htaccess 中使用正斜杠重定向 url?

[英]How to redirect url with forward slash in .htaccess?

I'm trying to redirect my url:我正在尝试重定向我的网址:

www.site.com/dashboard/invest-package.php?packageID=1

to

www.site.com/dashboard/invest-package/1

Actually I solved this problem with -其实我解决了这个问题-

<a href="invest-package-'.$row['packageID'].'">Invest</a>

RewriteRule ^invest-package-(.*)$ invest-package.php?packageID=$1 [QSA,L]

But I wanted to make with "/" don't like using "-".但我想用“/”做,不喜欢用“-”。 Solutions I found on the internet didn't work.我在互联网上找到的解决方案不起作用。 I keep getting 404 not found error.我不断收到 404 not found 错误。

Here is my link to invest-package.php这是我的投资包.php链接

<a href="invest-package/'.$row['packageID'].'">Invest</a>

and .htaccess file:和 .htaccess 文件:

Options -Indexes
RewriteEngine On

RewriteBase /dashboard/

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]

RewriteRule ^invest-package/(.*)$ invest-package.php?packageID=$1 [QSA,L]

You may try this code:你可以试试这个代码:

Options -Indexes -MultiViews
RewriteEngine On
RewriteBase /dashboard/

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^invest-package/([\w-]+)/?$ invest-package.php?packageID=$1 [QSA,L,NC]

It is important to turn off MultiViews ie the content negotiation service of Apache.关闭MultiViews即 Apache 的内容协商服务很重要。

Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html ) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files.选项MultiViews (参见http://httpd.apache.org/docs/2.4/content-negotiation.html )由Apache's content negotiation module ,该Apache's content negotiation modulemod_rewrite之前运行并使 Apache 服务器匹配文件的扩展名。 So if /file is the URL then Apache will serve /file.php without any GET parameters.因此,如果/file是 URL,则 Apache 将在没有任何GET参数的情况下提供/file.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM