需要重写 HTAccess

发布于 2024-09-15 20:15:50 字数 417 浏览 2 评论 0原文

我需要将我的域中以 **/club/***anyPage* 开头的所有网址重写为 /page/club/anyPage

为此,我相信我可以使用以下命令:

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

另外,如果物理页不存在,我希望它有条件地重写,如下所示:

/club/$1/page/club/club.php?title=$1

所以在这种情况下,如果用户进入 mysite.com/club/New_Club 他们实际上应该正在查看 /page/club/club.php?title=New_Club

I need to rewrite any url on my domain that starts with **/club/***anyPage* to /page/club/anyPage.

For this, I believe I can use the following command:

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

Also, if the physical page does not exist I want it conditionally rewritten like so:

/club/$1 to /page/club/club.php?title=$1

So in this case if the user enters in mysite.com/club/New_Club they should actually be viewing /page/club/club.php?title=New_Club

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

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

发布评论

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

评论(1

泪是无色的血 2024-09-22 20:15:50

您原来的规则似乎可以正常工作,但是为了纳入第二个要求,类似这样的东西应该可以完成工作......

# do first rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
# do second rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

或者取决于其他规则......

# prevent requests for real files / directories from rewritting at all
RewriteCond %{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} -d
RewriteRule .* - [L]

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]

Your original rules seems to work OK for it's job, but to encorporate the second requirement, something like this should do the job...

# do first rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
# do second rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

or depending on other rules...

# prevent requests for real files / directories from rewritting at all
RewriteCond %{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} -d
RewriteRule .* - [L]

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文