.htaccess RewriteRule to path without changing URL

后端 未结 2 582
轻奢々
轻奢々 2020-11-30 13:51

So, I\'ve this problem:

  1. Base Website located at http://example.com/
  2. Second Website located at http://example.com/web2/
相关标签:
2条回答
  • 2020-11-30 14:17

    Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^alternative-url-web2(/.*|)$ /web2$1 [L,NC]
    

    Alternate code:

    RewriteRule ^alternative-url-web2/?$ /web2/ [L,NC]
    RewriteRule ^alternative-url-web2/(.+)$ /web2/$1 [L,NC]
    
    0 讨论(0)
  • 2020-11-30 14:19

    This is a pretty simple rewrite. In the htaccess file in your document root, just add the following:

    RewriteEngine On
    RewriteRule ^alternative-url-web2/?(.*)$ /web2/$1 [L]
    

    Unlike a redirect, which makes the browser/client send a new request for a new URL (thus changing what's in the browser's location bar), a rewrite happens entirely on the server's side.

    0 讨论(0)
提交回复
热议问题