我的目标是获取格式为
的网址www.mydomain.com(/dir1)?(/dir2)?/(index.php|login.php)((:?\?code=)[a-Z0-9]+)?
强制将浏览器网址更改为:
www.mydomain.com/(home|welcomepage)/code/%1/
一个简单的例子是:
www.mydomain.com/dir1/dir2/index.php?code=khkdh239
更改为:
www.mydomain.com/home/code/khkdh239/
并将内部重定向到
www.mydomain.com/dir1/dir2/index.php?code=khkdh239
这是我的许多尝试之一;
#RewriteCond %{QUERY_STRING} !^$ # I was experimenting with simple urls, no ?code=....
#RewriteRule .? - [S=2]
RewriteRule ^(?:dir1/)?(?:dir2/)?(?:login.php)$ /welcomepage/? [R=301,NC]
RewriteRule ^.*welcomepage.*$ code/login.php? [QSA,L]
根据我的尝试结果进行观察:
规则
RewriteRule ^welcomepage/$ code/login.php? [QSA,L]
没有重定向,因此我使用了^.*welcomepage.*$
。
规则
RewriteRule ^(?:dir1/)?(?:dir2/)?(?:login.php)$ /welcomepage/? [R=301,NC,L]
RewriteRule ^.*welcomepage.*$ code/login.php? [QSA,L]
重定向到www.domain.com/welcomepage/
,但内部重定向失败。
规则
RewriteRule ^(?:dir1/)?(?:dir2/)?(?:login.php)$ /welcomepage/? [R=301,NC]
RewriteRule ^.*welcomepage.*$ code/login.php? [QSA,L]
重定向到第二个链接但不重定向到第一个链接。
POST
操作)。提前谢谢大家。
答案 0 :(得分:0)
最终的未精炼解决方案是anubhava,hjpotter92和我的组合。
如果有人遇到类似的问题,我将提供.httaccess
代码。
重要提示:可以找到所有重定向标志here([NC,R,P,L]等)。
因为我的.htacces文件位于/{ROOT_DIRECTORY_OF_SITE}/dir1/
而不是/{ROOT_DIRECTORY_OF_SITE}/
为了实现这一点,我遵循了hjpotter92建议,并检查了GET
对于THE_REQUEST
遵循特定正则表达式的所有R=301
次请求。在这些情况下,真实地址被转发到假地址。我使用R=302
,这是永久重定向,只有在我确定它是正确的时候。调试时使用# Redirect dir1/dir2/login.php?code=password to fake address mydomain.com/signup/?code=password
RewriteCond %{THE_REQUEST} GET\ /?(?:dir1/)?(?:dir2/)?login\.php\?code=([^&]+) [NC]
RewriteRule ^.*$ /signup/%1/ [R=301,L]
#Redirect fake address mydomain.com/signup/?code=pasword internaly to real address
RewriteRule ^signup/([^/]+)/$ /dir1/dir2/login.php?code=$1 [NC,L]
和隐私浏览。
url
在这里,我必须有点创意。在文件上传的表单中,我将重定向更改为指向虚假,美化 mydomain.com/signup/send-mail/#login
。
例如,将帖子请求发送到我使用的<form role="form" method="POST" action="/signup/send-mail/#login" id="login">
:
.htaccess
然后在url
文件中,我将假的RewriteRule ^signup/email-sent/ /dir1/dir2/login.php#login [NC,P]
请求重定向到真实的请求。
[P]
[L]
标志等同于[L]
,但它也允许POST数据重定向,因为它作为代理。 .htaccess
标志只是告诉系统不要在Options -Indexes
DirectoryIndex ./dir1/dir2/index.php
RewriteEngine on
# Redirect dir1/dir2/login.php?code=password to fake address mydomain.com/signup/?code=password
RewriteCond %{THE_REQUEST} GET\ /?(?:dir1/)?(?:dir2/)?login\.php\?code=([^&]+) [NC]
RewriteRule ^.*$ /signup/%1/ [R=301,L]
#Redirect fake address mydomain.com/signup/?code=pasword internaly to real address
RewriteRule ^signup/([^/]+)/$ /dir1/dir2/login.php?code=$1 [NC,L]
# Redirect dir1/dir2/login.php to fake address mydomain.com/signup/
RewriteCond %{THE_REQUEST} GET\ /?(?:dir1/)?(?:code/)?login\.php [NC]
RewriteRule ^.*$ /signup/ [R=302,L]
#Redirect fake address mydomain.com/signup/ internaly to real address
RewriteRule ^signup/$ /dir1/dir2/login.php [NC,L]
# Redirect dir1/dir2/index.php?code=password to fake address mydomain.com/home/?code=password
RewriteCond %{THE_REQUEST} GET\ /?(?:dir1/)?(?:code/)?index\.php\?code=([^&]+) [NC]
RewriteRule ^.*$ /home/%1/ [R=302,L]
# Redirect the fake address mydomain.com/home/?code=password to a real one, internaly
RewriteRule ^home/([^/]+)/$ /dir1/dir2/index.php?code=$1 [NC,L]
# Redirect dir1/dir2/index.php to fake address mydomain.com/home/
RewriteCond %{THE_REQUEST} GET\ /?(?:dir1/)?(?:code/)?index\.php [NC]
RewriteRule ^.*$ /home/ [R=302,L]
# Redirect the fake address mydomain.com/home/ to a real one, internaly
RewriteRule ^home/$ /dir1/dir2/index.php [NC,L]
# Redirect the fake address mydomain.com/signup/email-sent/ to a realone
RewriteRule ^signup/email-sent/ /dir1/dir2/login.php#login [NC,P]
# Redirect the fake address mydomain.com/home/file-uploaded/ to a realone
RewriteRule ^home/file-uploaded/ /dir1/dir2/index.php#page-demo-upload [NC,P]
文件中继续向下,因为这将是最后一次重定向(简单来说,详情请参考documentation)。
.htaccess
非常感谢所有回复我帖子并帮助我达到public static void main(String[] args)
{
int start;
int end;
int start2;
int end2;
start = Integer.parseInt(args[0]);
end = Integer.parseInt(args[1]);
start2 = start*start;
end2 = end*end;
if (args.length == 2) {
for (int i = start; i <= end; i++){
System.out.println("The square of "+start+" is " +start2);
System.out.println("The square of "+end+ " is " +end2);
return;
}
}
版本的人。