PHP /阿帕奇:重写与的.htaccess规则重写、阿帕奇、规则、PHP

2023-09-02 09:52:16 作者:万人宠不如一人懂

我有一点与mod_rewrite的一个困境。 如何编写一个规则,将决定如下:

如果我浏览 / EN /页/页我想改写这个来: ?的index.php语言= EN&放大器;页= /页

但是,如果我只是浏览 /页我想改写这个来: 的index.php?页= /页

这可能吗?

编辑: /网页是一个随机动态的页面名,它可以藏汉是任何

我需要一个规则,检查象/ SE ==字符串,最长不超过2个字符> /页 - >的index.php LANG = SE&放大器;页= /页,如果浏览网页/网页会通知那/页==超过200个字符和重写到index.php?页= /页

EDIT2: 找到了雁我的问题:


    RewriteEngine叙述上
    的RewriteBase /

    ##检查它不是一个文件名或目录名
    的RewriteCond%{} REQUEST_FILENAME!-l
    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d

    ##重写规则
    重写规则^({2})/(。*)$的index.php?LANG = $ 1页= $ 2 [L]
    重写规则^(。*)$的index.php?网页= $ 1 [L,QSA]

解决方案

我得到它的工作在我自己的! 这里的规则,如果别人需要做同样的事情:

    RewriteEngine叙述上
    的RewriteBase /

    ##检查它不是一个文件名或目录名
    的RewriteCond%{} REQUEST_FILENAME!-l
    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d

    ##重写规则
    重写规则^({2})/(。*)$的index.php?LANG = $ 1页= $ 2 [L]
    重写规则^(。*)$的index.php?网页= $ 1 [L,QSA]
求解PHP下载之后怎么解压到阿帕奇的主目录下啊

I have a bit of a dilemma with mod_rewrite. How do I write a rule that will decide the following:

If i browse /en/page/page I want to rewrite this to: index.php?language=en&page=/page

BUT if i browse just /page I want to rewrite this to: index.php?page=/page

Is this possible?

Edit: /page is just a random dynamic pagename, it could aswell be whatever.

I need a rule that checks like /se == a string, and not longer than 2 characters>/page --> index.php?lang=se&page=/page and if browsing page /page it will notice that /page == longer than 2 characters and rewrite to index.php?page=/page

Edit2: Found the anser to my question:


    RewriteEngine On
    RewriteBase /

    ## Check if its not a filename or dirname
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    ## Rewrite rules
    RewriteRule ^(.{2})/(.*)$ index.php?lang=$1&page=$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

解决方案

I got it to work on my own! Here's the rules if someone else needs to make the same thing:

    RewriteEngine    On
    RewriteBase    /

    ## Check if its not a filename or dirname
    RewriteCond %{REQUEST_FILENAME}    !-l
    RewriteCond %{REQUEST_FILENAME}    !-f
    RewriteCond %{REQUEST_FILENAME}    !-d

    ## Rewrite rules
    RewriteRule ^(.{2})/(.*)$    index.php?lang=$1&page=$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]