dongmou9260 2015-08-21 21:34
浏览 18

Htaccess没有使用两个斜杠

I try to make a custom link like:

mysite.com/users/test

I have the following code in my .htaccess file:

    Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)$ index.php?h=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ index.php?h=$1&p=$2 [QSA,L]

My problem is: with one "/something" is working, the index.php loads correctly but with "/something/test" I'm gettin a Uncaught SyntaxError: Unexpected token <.

Thankyou.

  • 写回答

1条回答 默认 最新

  • dongsonghen9931 2015-08-21 22:06
    关注

    I think the "\/" in the following is incorrect.

    RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ index.php?h=$1&p=$2 [QSA,L]
    

    I think that should be: RewriteRule ^([A-Za-z0-9\_\-]+)/(.*)$ index.php?h=$1&p=$2 [QSA,L]

    One thing to note with your definitions is that there is no RewriteBase directive specified and the index.php portion would usually be preceded by a leading slash - which leads to:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([A-Za-z0-9\_\-]+)$ /index.php?h=$1 [QSA,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^([A-Za-z0-9\_\-]+)/(.*)(/?)$ /index.php?h=$1&p=$2 [QSA,L]
    

    Tested this using the url https://localhost/something/somethingelse/blahblah/?page=1 which showed the following GET variables:-

    Array
    (
        [h] => something
        [p] => somethingelse/blahblah
        [page] => 1
    )
    
    评论

报告相同问题?