search

Home  >  Q&A  >  body text

javascript - htaccess rewrite problem

I have a website developed by thinkphp, and I use mod rewrite

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteRule ^(.*)$ index.php/ [QSA,PT,L]

</IfModule>

thinkphp and the program are running normally. Now my requirement is that I put a small program developed by vue in the hot directory of the root directory of the website, and turned on the history routing mode.
Follow the development documentation in order to allow All paths can be recognized by the server, and all accesses must be rewritten to index.hml through RewriteRule

That is to say, we need to parse a url like http://wwww.xxx.com/hot/item/1000 to /hot/index.html,
Others are still controlled by thinkphp.
I have tried many configurations but nothing works. I am not familiar with .htaccess file commands, so I hope everyone can give me a solution

Reply to the content on the first floor, I will also post it here
vue is running normally. When the history mode is turned on, you enterhttp://www.xxx.com/hotIt can run normally, and you can jump normally when clicking on each link, because the history mode of html5 only changes the url address bar in the browser section, and does not request data from the server, but when the user directly uses http://www When accessing a url like .xxx.com/hot/item/1000, it will not be returned normally because there is no such file on the server. However, through the htaaccess file of apache, users can jump to files that do not exist. Go to the specified file, just like the configuration file under thinkphp I posted above plays this role. My current requirement is not to forward the request in the /hot directory to thinkphp for execution, but forward it to /hot/ index.html to handle.

I tried the following

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
  
  RewriteCond %{REQUEST_URI} ^/(hot|hot/.*)$
  RewriteRule ^/hot/index\.html$ - [L]

  RewriteRule ^(hot|hot/.*)$ hot/index.html$ [L]

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteRule ^hot/(.*)$ hot/index.html$
  #RewriteRule ".?" "-" [S=1]
  #RewriteRule ^/(hot|hot/.*)$ /hot/index.html$ [L]
  RewriteRule ^(.*)$ index.php/ [QSA,PT,L]

</IfModule>

But it doesn’t work, don’t know why?

phpcn_u1582phpcn_u15822743 days ago465

reply all(2)I'll reply

  • 为情所困

    为情所困2017-05-16 16:59:11

    If you don’t know much about thinkphp, you can take a look at thinkphp’s routing configuration to see if you can specify different routing schemes for a certain directory

    If that doesn’t work, you may have to use nginx

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 16:59:11

    Solved, my original idea was right, index.php which was always parsed to the home directory at first turned out to be my reference resource path problem
    Post the valid configuration

    <IfModule mod_rewrite.c>
      Options +FollowSymlinks
      RewriteEngine On
      
      RewriteCond %{REQUEST_URI} ^/(hot|hot/.*)$
      RewriteRule ^/hot/index\.html$ - [L,NC]
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(hot|hot/.*)$ hot/index.html [L]
    
      RewriteCond %{REQUEST_URI} !^/(hot|hot/.*)$
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ index.php/ [QSA,PT,L]
    
    </IfModule>

    Test address: http://www.wx2share.com/hot/
    If you enter directly through the above URL without doing url rewrite, all functions will be normal,

    But if you enter through the following URL
    http://www.wx2share.com/hot/i...
    , it will return 404, but after url rewrite, you can access it normally

    reply
    0
  • Cancelreply