За последние 24 часа нас посетили 16642 программиста и 1681 робот. Сейчас ищут 835 программистов ...

Переписать $_GET в ЧПУ (htaccess)

Тема в разделе "PHP для новичков", создана пользователем siuzi_drum, 3 апр 2013.

  1. siuzi_drum

    siuzi_drum Активный пользователь

    С нами с:
    18 янв 2012
    Сообщения:
    14
    Симпатии:
    0
    Здравствуйте!
    есть адрес такого типа -
    http://modx.test/index.html?act=go&quest=1
    как прописать в htaccess следующее правило:
    1 - http://modx.test/ - домен может менятся
    2 - index.html - адрес страницы может менятся (скрипт вызывается на разных страницах)
    3 - $_GET['act'] может быть go или end
    4 - $_GET['quest'] это целое число от 1 до хз...

    Последний раз пробовал так:
    Код (Text):
    1. RewriteRule ^/([_A-Za-z0-9]+)/([_A-Za-z0-9]+)$ ?act=$1&quest=$2 [L,QSA,R]
    и так
    Код (Text):
    1. RewriteRule ^.htaccess$ - [F]
    2. RewriteCond %{QUERY_STRING} ([_A-Za-z0-9]+)/([0-9]+)
    3. RewriteRule ^index\.html?$  index.html?act=$1&quest=$2 [L]
    и даже так
    Код (Text):
    1.  
    2.  
    3. RewriteCond %{QUERY_STRING} ^act=go$
    4. RewriteRule ^(.*)$ /test-start.html? [R=301,L]
    5. RewriteRule ^test-start.html/$ /test-start.html? [R=301,L]
    6. RewriteRule ^/test-start/ act=go
    Последний этот пример работает, но отдает 404 ошибку. И там еще quest не передан. Я немного в замешательстве. Подскажите, пожалуйста
    код htaccess
    Код (Text):
    1. # For full documentation and other suggested options, please see
    2. # http://svn.modxcms.com/docs/display/MODx096/Friendly+URL+Solutions
    3. # including for unexpected logouts in multi-server/cloud environments
    4. # and especially for the first three commented out rules
    5.  
    6. #php_flag register_globals Off
    7. AddDefaultCharset utf-8
    8. #php_value date.timezone Europe/Moscow
    9.  
    10. Options +FollowSymlinks
    11. RewriteEngine On
    12. RewriteBase /
    13.  
    14. # Fix Apache internal dummy connections from breaking [(site_url)] cache
    15. RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
    16. RewriteRule .* - [F,L]
    17.  
    18. # Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
    19. #RewriteCond %{HTTP_HOST} .
    20. #RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
    21. #RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    22.  
    23. # without www
    24. #RewriteCond %{HTTP_HOST} .
    25. #RewriteCond %{HTTP_HOST} !^example\.com [NC]
    26. #RewriteRule (.*) http://example.com/$1 [R=301,L]
    27.  
    28. # Exclude /assets and /manager directories and images from rewrite rules
    29. RewriteRule ^(manager|assets|js|css|images|img)/.*$ - [L]
    30. RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]
    31.  
    32. # For Friendly URLs
    33. RewriteCond %{REQUEST_FILENAME} !-f
    34. RewriteCond %{REQUEST_FILENAME} !-d
    35. RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    36.  
    37. # Reduce server overhead by enabling output compression if supported.
    38. #php_flag zlib.output_compression On
    39. #php_value zlib.output_compression_level 5
     
  2. Your

    Your Старожил

    С нами с:
    2 июл 2011
    Сообщения:
    4.074
    Симпатии:
    7
    До PHP_INT_MAX - int(2147483647).

    :D
     
  3. siuzi_drum

    siuzi_drum Активный пользователь

    С нами с:
    18 янв 2012
    Сообщения:
    14
    Симпатии:
    0
    Не могли не удержаться?
    =)
    А если по теме помочь?
     
  4. MouseZver

    MouseZver Суперстар

    С нами с:
    1 апр 2013
    Сообщения:
    7.819
    Симпатии:
    1.333
    Адрес:
    Лень
    примерчик можно? ))
    до
    и
    после
    например )
     
  5. siuzi_drum

    siuzi_drum Активный пользователь

    С нами с:
    18 янв 2012
    Сообщения:
    14
    Симпатии:
    0
    да, конечно
    http://modx.test/index.html?act=go&quest=1 и http://modx.test/index.html?act=end
    в
    http://modx.test/index/test-go/1 И http://modx.test/index/test-end (по окончанию тестирования)

    то есть адрес 1 вопроса тестирования имеет вид
    http://modx.test/index.html?act=go&quest=1
    2 вопроса
    http://modx.test/index.html?act=go&quest=2
    3 вопроса
    http://modx.test/index.html?act=go&quest=3
    =)
    если на другой странице то
    http://modx.test/drugaya_stranica.html?act=go&quest=1