Mod_rewrite 显示来自通配符域的重定向

发布于 2024-09-16 03:15:14 字数 1108 浏览 7 评论 0原文

我正要把 mod_rewrite 踢到路边。谈论“与他人相处不好”。有没有相关的巫医可以帮我解决这个问题?

我设置了通配符 dns 来识别用户。我想从:

http://username.domain.com/foo/bar

至:

https://www.domain.com/qux/waldo/username/ foo/bar

这可能吗?

我正在使用 codeigniter 进行开发,它已经在 .htaccess 中拥有自己的 mod_rewrite 指令,以删除 index.php。

这是我所得到的:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.idseal\.local.*$
RewriteRule (.*) /site/assign/$1

#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

I am so about to kick mod_rewrite to the curb. Talk about "doesn't play well with others." Are there any witchdoctors about that can help me with this?

I have wildcard dns set up to identify users. I would like to go from:

http://username.domain.com/foo/bar

to:

https://www.domain.com/qux/waldo/username/foo/bar

Is this possible?

I'm developing with codeigniter and it has it's own mod_rewrite directives in .htaccess already, to strip out the index.php.

Here's what I've got:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.idseal\.local.*$
RewriteRule (.*) /site/assign/$1

#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

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

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

发布评论

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

评论(1

昇り龍 2024-09-23 03:15:14

第一行验证我们是否在主域上,第二行将匹配是否有 www,如果有 www,它将保留在 %1 上,因此如果有 inst,则不进行任何更改,数据将被写入%2 并且会重写得很好。

我不能 100% 确定这会满足您的需求,但请尝试一下并报告回来,我会尽力帮助您。

RewriteEngine on

RewriteCond %{http_host} !^www.domain.com [NC]
RewriteCond %{http_host} ^(www.)?([^.]+).domain.com [NC]
RewriteRule (.*) https://www.domain.com/qux/waldo/%2/$1

First line verify if we are on the main domain or not, second line will match if there is a www or not, if there is a www it will be held on %1 thus making no changes if there inst, the data will be into %2 and will rewrite just fine.

I am not 100% sure this will work out for your needs but give it a try and report it back and i will try to assist you with what i can.

RewriteEngine on

RewriteCond %{http_host} !^www.domain.com [NC]
RewriteCond %{http_host} ^(www.)?([^.]+).domain.com [NC]
RewriteRule (.*) https://www.domain.com/qux/waldo/%2/$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文