.htaccess 下划线连字符在我的网络服务器中不起作用

.htaccess underscores to hyphens not working in my web server

关于我的案例,我已经看到很多 sample/tutorial,但是当我使用他们的工作代码时,它对我的​​ URL 没有任何作用。

我想把这个linkexample/lmp/property/jumeirah_parklarge_legacy_4brms/V0004221/变成example/lmp/property/jumeirah-parklarge-legacy-4brms/V0004221/

我还在 http://htaccess.madewithlove.be/ 中测试了 .htaccess 代码,它给了我正确的输出 URL 但是在我的本地服务器上测试时它没有重定向我输出 URL .

这是我的代码,

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /lmp


    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property------ [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property----- [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property---- [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property--- [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_(.*)$ lmp/property-- [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_(.*)$ lmp/property- [L,NC,E=underscores:Yes]

    RewriteCond %{ENV:REDIRECT_underscores} ^Yes$
    RewriteRule ^([^_]+)$ lmp/ [R,L]



    RewriteCond %{REQUEST_URI} ^../system.*
    RewriteRule ^(.*)$ /index.php?/ [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.

    RewriteCond %{REQUEST_URI} ^../application.*
    RewriteRule ^(.*)$ /index.php?/ [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/ [L]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
    RewriteRule ^ %1/%2 [R=301,L]

</IfModule>
<IfModule !mod_rewrite.c>

    ErrorDocument 404 /home
</IfModule>

您可以使用:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /lmp/

    # recursive rule to replace _ by - from REQUEST_URI
    RewriteRule ^(property)/([^_]*)_+([^_]*_.*)$ /- [L,NC]
    RewriteRule ^(property)/([^_]*)_([^_]*)$ /- [L,R=302,NC,NE]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
    RewriteRule ^ %1/%2 [R=301,L]

    RewriteCond %{REQUEST_URI} ^../system.*
    RewriteRule ^(.*)$ /index.php?/ [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.

    RewriteCond %{REQUEST_URI} ^../application.*
    RewriteRule ^(.*)$ /index.php?/ [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/ [L]

</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /home
</IfModule>