我正在尝试编写.htaccess代码,该代码将忽略URL的最终子目录,路由到该最终子目录之前的目录,但保持URL完整。
这是在SPA的上下文中,我使用JavaScript进行路由。
如果我导航到目录xxx,该目录可以任意嵌套:
https://my-site/[subdirectories]/xxx
...然后单击xxx目录中的相对链接,例如:
./aaa
./bbb
./ccc
...将与之对应(并产生URL)
https://my-site/[subdirectories]/xxx/aaa
https://my-site/[subdirectories]/xxx/bbb
https://my-site/[subdirectories]/xxx/ccc
...然后,JavaScript将检测到URL中的更改并显示“虚拟”子目录aaa
,bbb
,ccc
的内容。很好,花花公子。
但是,如果我直接进入任何这些URL,即直接输入URL,而不是在网站内使用导航,则我的网站会抛出404错误,如aaa
,{{1 }}和bbb
不是实际的子目录。它们是“虚拟”子目录,与服务器上的实际文件夹不对应,因此会引发错误。
我想编写一个.htaccess例程,该例程将检测初始导航(直接打开):
ccc
等
...然后只需打开此位置:
https://my-site/[subdirectories]/xxx/aaa
https://my-site/[subdirectories]/xxx/bbb
https://my-site/[subdirectories]/xxx/ccc
...但保留URL栏中显示的URL末尾的“虚拟”子目录(https://my-site/[subdirectories]/xxx
,aaa
,bbb
)。我的JavaScript将接管那里,为ccc
,aaa
,bbb
引入所需的内容。 (而且,在直接直接导航到ccc
,然后简单地单击指向https://my-site/[subdirectories]/xxx
,aaa
,bbb
的链接之后,这种方法就很好了;它将直接转到这些“子目录”中的任何一个那就是问题。)
可以使用.htaccess完成吗?我在挣扎。
答案 0 :(得分:0)
诀窍是制定一个重写规则,为目标内容指定一个文件。
如果子目录名称已知,并且在本示例中为def ok(Event = None):
try:
start_to_time = datetime.datetime.strptime(str(input_start_time.get()), "%H:%M")
lunch_duration = str( input_lunch_time.get() )
lunch_to_time = datetime.timedelta(hours=lunch_duration[0], minutes=lunch_duration[1])
close_to_time = datetime.datetime.strptime(str(input_closing_time.get()), "%H:%M")
x = (close_to_time - start_to_time) - lunch_to_time
print(x)
return x
,aaa
和bbb
,则以下规则将在子目录中打开index.html文件,同时保留完整的网址:
ccc