.htaccess强调连字符在我的Web服务器中不起作用

时间:2015-01-04 08:59:29

标签: .htaccess

我看过很多关于我案例的示例/教程,但是当我使用他们的工作代码时,它没有对我的网址做任何事情。

我想建立这个链接示例/ lmp / property / jumeirah_parklarge_legacy_4brms / V0004221 /示例/ lmp / property / jumeirah-parklarge-legacy-4brms / V0004221 /

我还测试了http://htaccess.madewithlove.be/中的.htaccess代码,它为我提供了正确的输出网址,但在我的本地服务器上进行测试时,它并没有将我重定向到输出网址。

这是我的代码,

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


    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4-$5-$6-$7 [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4-$5-$6 [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4-$5 [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3-$4 [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_([^_]*)_(.*)$ lmp/property$1-$2-$3 [L,NC,E=underscores:Yes]
    RewriteRule ^lmp/property([^_]*)_(.*)$ lmp/property$1-$2 [L,NC,E=underscores:Yes]

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



    RewriteCond %{REQUEST_URI} ^../system.*
    RewriteRule ^(.*)$ /index.php?/$1 [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?/$1 [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?/$1 [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>

1 个答案:

答案 0 :(得分:0)

您可以使用:

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

    # recursive rule to replace _ by - from REQUEST_URI
    RewriteRule ^(property)/([^_]*)_+([^_]*_.*)$ $1/$2-$3 [L,NC]
    RewriteRule ^(property)/([^_]*)_([^_]*)$ $1/$2-$3 [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?/$1 [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?/$1 [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?/$1 [L]

</IfModule>

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