URL-rewriting with index in a “public” folder

前端 未结 1 1758
北荒
北荒 2021-01-26 23:40

I’m a newcomer in the development world. I desperately try to get the good URL. I checked the site for similar problems but I can’t find exactly what I need. Or I do it badly.

相关标签:
1条回答
  • 2021-01-27 00:01

    Not really sure what you are trying to do, but if you want to remove the /public/ path that appears in the URL, you need to remove it from all your links, second, turn off multiviews, it's not what you want, third, you need a rule to externally redirect the browser when a request is made for /public/, then you need to internally rewrite requests to point to public.

    Options -Indexes +FollowSymLinks -Multiviews
    RewriteEngine On
    
    # externally redirect, must match against %{THE_REQUEST}
    RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /public/
    RewriteRule ^/?public/(.*)$ /$1 [L,R=301]
    
    # internally rewrite it back, but we must first check that it's pointing to a valid resource:
    RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -d [OR]
    RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -s
    RewriteRule ^(.*)$ /public/$1 [L]
    
    0 讨论(0)
提交回复
热议问题