使用htaccess文件从url创建url变量

时间:2013-04-23 17:38:44

标签: .htaccess mod-rewrite

我想编写一个htaccess文件,它接受输入链接并将它们转换为输出(这基本上是在/ test /之后添加的东西?location =

输入

  1. http://test.co.uk/test/uk/england/london
  2. http://test.co.uk/test/uk/england
  3. http://test.co.uk/test/uk/england/london/soho
  4. 至:(输出)

    1. http://test.co.uk/test/?location=uk/england/london
    2. http://test.co.uk/test/?location=uk/england
    3. http://test.co.uk/test/?location=uk/england/london/soho

1 个答案:

答案 0 :(得分:2)

测试目录的htaccess文件中,添加:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?location=$1 [L]

或者在文档根目录中的htaccess文件中:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/(.*)$ /test/?location=$1 [L]