mod_rewrite查询字符串不在本地工作

时间:2013-01-11 20:42:37

标签: forms codeigniter mod-rewrite get url-parameters

我需要使用mod_rewrite进行翻译:

http://example.com/sitengoFrontEnd3/lista/tipo-todo/?terminos=abcd

分为:

http://example.com/sitengoFrontEnd3/lista/tipo-todo/abcd

我正在使用codeigniter框架。

我的.htaccess是:

RewriteEngine On
RewriteBase /sitengoFrontEnd3

# Esto es para el formulario de busqueda
RewriteCond %{QUERY_STRING} terminos=(.*)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1%1? [L]

# Esto para el codeigniter
RewriteCond %{REQUEST_URI} ^sitengoFrontEnd3.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

在这种情况下:

浏览:

http://example.com/sitengoFrontEnd3/lista/tipo-todo/?terminos=abcd

结果(相同):

http://example.com/sitengoFrontEnd3/lista/tipo-todo/?terminos=abcd

我粘贴LogRewrite Level 9:

(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] add path info postfix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/lista -> /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/lista/tipo-todo/
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] strip per-dir prefix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/lista/tipo-todo/ -> lista/tipo-todo/
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] applying pattern '^(.*)$' to uri 'lista/tipo-todo/'
(4) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] RewriteCond: input='terminos=abcd' pattern='terminos=(.*)'  > matched
(4) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] RewriteCond: input='/Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/lista' pattern='!-f' => matched
(4) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] RewriteCond: input='/Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/lista' pattern='!-d' => matched
(2) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] rewrite 'lista/tipo-todo/' -> 'index.php/lista/tipo-todo/abcd?'
(3) split uri=index.php/lista/tipo-todo/abcd? -> uri=index.php/lista/tipo-todo/abcd, args=<none>
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] add per-dir prefix: index.php/lista/tipo-todo/abcd -> /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd
(2) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] trying to replace prefix /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/ with /sitengoFrontEnd3
(5) strip matching prefix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd -> index.php/lista/tipo-todo/abcd
(4) add subst prefix: index.php/lista/tipo-todo/abcd -> /sitengoFrontEnd3/index.php/lista/tipo-todo/abcd
(1) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] internal redirect with /sitengoFrontEnd3/index.php/lista/tipo-todo/abcd [INTERNAL REDIRECT]
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] add path info postfix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php -> /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] strip per-dir prefix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd -> index.php/lista/tipo-todo/abcd
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] applying pattern '^(.*)$' to uri 'index.php/lista/tipo-todo/abcd'
(4) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] RewriteCond: input='' pattern='terminos=(.*)' => not-matched
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] add path info postfix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php -> /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] strip per-dir prefix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd -> index.php/lista/tipo-todo/abcd
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] applying pattern '^(.*)$' to uri 'index.php/lista/tipo-todo/abcd'
(4) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] RewriteCond: input='/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd' pattern='^sitengoFrontEnd3.*' => not-matched
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] add path info postfix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php -> /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] strip per-dir prefix: /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php/lista/tipo-todo/abcd -> index.php/lista/tipo-todo/abcd
(3) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] applying pattern '^(.*)$' to uri 'index.php/lista/tipo-todo/abcd'
(4) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] RewriteCond: input='/Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php' pattern='!-f' => not-matched
(1) [perdir /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/] pass through /Applications/XAMPP/xamppfiles/htdocs/sitengoFrontEnd3/index.php

如果我更改.htaccess的这一行:

RewriteRule ^(.*)$ index.php/$1%1? [L]

对于另一个外部的:

RewriteRule ^(.*)$ http://example2.com/$1%1? [L]

然后,当我浏览到:

http://example.com/sitengoFrontEnd3/lista/tipo-todo/?terminos=abcd

结果:

http://example2.com/lista/tipo-todo/abcd

那么,为什么它适用于外部和绝对,而不适用于内部和外部有关系吗? 我失去了一天试图解决这个问题没有成功,所以欢迎任何帮助。

1 个答案:

答案 0 :(得分:0)

确定。 谢谢您的意见。 最后我用以下内容解决了.htaccess:

    RewriteEngine On
    RewriteBase /sitengoFrontEnd3


    # Esto es para el formulario de busqueda
    #RewriteCond %{REQUEST_URI} ^sitengoFrontEnd3.*
    RewriteCond %{QUERY_STRING} terminos=(.*)
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ %{REQUEST_URI}%1? [R=301,L]



    # Esto para el codeigniter
    RewriteCond %{REQUEST_URI} ^sitengoFrontEnd3.*
    RewriteRule ^(.*)$ /index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]