modrewrite 网站在 .htaccess 中带有斜线

发布于 2024-12-28 05:45:11 字数 620 浏览 2 评论 0原文

我如何翻译如下 URL: http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink =详细信息

至: http://localhost/mySite/OFFERS/ARTICLE/DETAIL

如果一个参数为空,它仍然应该像这样工作: localhost/mySite/?link=OFFERS&sublink=ARTICLE localhost/mySite/OFFERS/ARTICLE

额外问题:index.php 下有一个输入页面,重写应该适用于index2.php。最好的情况是它可以在本地主机和实时系统上运行而无需更改。

目前我正在使用: RewriteRule ^([^/.]+)$ index2.php?link=$1 [L] 但这只适用于一个参数,而且我很长时间都无法改进这段代码^^

How can I translate an URL like:
http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL

to:
http://localhost/mySite/OFFERS/ARTICLE/DETAIL

if one parameter is empty it should still work like this:
localhost/mySite/?link=OFFERS&sublink=ARTICLE
localhost/mySite/OFFERS/ARTICLE

Extra problem: There is an enter page under index.php and the rewrite should work with index2.php. Best would be if it would work under localhost and on live system without changes.

Currently I'm using: RewriteRule ^([^/.]+)$ index2.php?link=$1 [L]
But that only works for one parameter and I couldn't improve this code for ages ^^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神妖 2025-01-04 05:45:11
RewriteRule ^([^/.]+)(/([^/.]+))?(/([^/.]+))?$ index2.php?link=$1&sublink=$3&subsublink=$5 [L,QSA]

请注意,localhost/mySite/OFFERS/ARTICLE 链接到 localhost/mySite/?link=OFFERS&sublink=ARTICLE&sussublink= 而不是 localhost/mySite/? link=OFFERS&sublink=ARTICLE
应该不是一个大问题,但请确保 PHP 代码不会使用 isset($_GET['subsublink'])

RewriteRule ^([^/.]+)(/([^/.]+))?(/([^/.]+))?$ index2.php?link=$1&sublink=$3&subsublink=$5 [L,QSA]

Note that localhost/mySite/OFFERS/ARTICLE links to localhost/mySite/?link=OFFERS&sublink=ARTICLE&sussublink= and not localhost/mySite/?link=OFFERS&sublink=ARTICLE.
Should not be a big issue, but make sure the PHP code doesn't us isset($_GET['subsublink']).

一直在等你来 2025-01-04 05:45:11

尝试将以下内容添加到站点 mysite 目录中的 htaccess 文件中。

RewriteEngine on
RewriteBase /mysite/

# rewrite http://localhost/mySite/OFFERS/ARTICLE/DETAIL to
# http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
#assumes that index2.php is in the root directory of site
RewriteRule ^([-a-zA-Z0-9])+/([-a-zA-Z0-9])+/([-a-zA-Z0-9])+ index2.php?link=$1&sublink=$2&subsublink=$3 [NC,L]

#redirect index to index2
#if you do not want to redirect, just server rewrite, remove the R=301 below
RewriteRule ^index\.php$ index2.php [NC,L,R=301]

Try adding the following to your htaccess file in the mysitedirectory of your site.

RewriteEngine on
RewriteBase /mysite/

# rewrite http://localhost/mySite/OFFERS/ARTICLE/DETAIL to
# http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
#assumes that index2.php is in the root directory of site
RewriteRule ^([-a-zA-Z0-9])+/([-a-zA-Z0-9])+/([-a-zA-Z0-9])+ index2.php?link=$1&sublink=$2&subsublink=$3 [NC,L]

#redirect index to index2
#if you do not want to redirect, just server rewrite, remove the R=301 below
RewriteRule ^index\.php$ index2.php [NC,L,R=301]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文