简体   繁体   中英

how to replace all the ? and = by / htaccess

hello all i have a site in which i would like to replace all the ? and = of urls by / . i know this cn be done by htaccess file but i am very new to htaccess

i have this code in my htaccess file

ErrorDocument 404 /error404.php
ErrorDocument 403 /error404.php
 Options -Indexes 
 RewriteEngine On
 RewriteBase /

  RewriteCond %{REQUEST_METHOD} POST [NC]
  RewriteRule ^ - [L]

 RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC] 
  RewriteRule \.(gif|jpg|jpeg)$ http://www.domain.com [L]

  RewriteCond %{HTTP_HOST} !^www\.
 RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

  RewriteCond %{THE_REQUEST} \s/+(page1)\.php\?eid=(78)[&\s] [NC]
  RewriteRule ^ /%1/%2? [R=301,L]
   RewriteRule ^(page1)/(\d+)$ /$1.php?eid=$2 [L,QSA,NC]

     RewriteCond %{THE_REQUEST} \s/+page2\.php\?url=([^\s&]+) [NC]
   RewriteRule ^ /%1? [R=301,L]

     RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
     RewriteRule ^ /%1 [R=302,L,NE]

     RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
 RewriteRule ^(.+?)/?$ /$1.php [L]

   RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)$ /page2.php?url=$1 [L,QSA]

thnkx in advance ... i wana replace all the ? and = of the url by / like

    domain.com/page.php?id=44 by 
    domain.com/page/id/4

First off, you need to clarify what you intend to accomplish.

If you intend to have the user visit domain.com/page/id/4 and have it internally be rewritten to page.php?id=4 , then you have two options:

1) use a rewrite rule, such as:

RewriteRule ^/?page/([^/]+)/(.+)$ page.php?$1=$2

2) (preferred) use MultiViews and have your php script do the logic for you by parsing the

REQUEST_URI ($_SERVER['REQUEST_URI']).

First off, you need to clarify what you intend to accomplish.

If you intend to have the user visit domain.com/page/id/4 and have it internally be rewritten to page.php?id=4, then you have two options:

1) use a rewrite rule, such as:

RewriteRule ^/?page/([^/]+)/(.+)$ page.php?$1=$2 2) (preferred) use MultiViews and have your php script do the logic for you by parsing the

REQUEST_URI ($_SERVER['REQUEST_URI']).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM