mod_rewrite to index.html breaks relative paths for deep URLs

前端 未结 3 1061
轻奢々
轻奢々 2020-12-16 08:41

For a single-page app, I have the following RewriteRule in my .htaccess file to direct all traffic to index.html so that a JS can parse the URL and fire controllers accordin

3条回答
  •  青春惊慌失措
    2020-12-16 09:26

    I also wanted all URL's routed to the same file on my server, and found this. The code provided there does exactly what you're after. Here is that code:

    Options +FollowSymLinks
    IndexIgnore */*
    # Turn on the RewriteEngine
    RewriteEngine On
    #  Rules
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php
    

    This would route everything to index.php. Just change it to index.html for your purposes, and I think that will work.

    BTW, something like "www.mydomain.com/more/nested/resource/123" would be routed successfully.

提交回复
热议问题