替换?通过/在网址中,让他们更友好

时间:2016-02-07 17:14:54

标签: .htaccess redirect

你好,我有一个像

的网址
 http://www.domain.com/dash?do=about&w=me

但我想像

那样
  http://www.domain.com/dash/about/me

我在htaccess文件中有这些东西。

     RewriteEngine On
     RewriteBase /
     Options All -Indexes
     RewriteCond %{REQUEST_METHOD} POST [NC]
    RewriteRule ^ - [L]
      ErrorDocument 403 /www.domain.com/error404.php
       RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC] 

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

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

     # redirect /profile?eid=1 to /eid/1
   RewriteCond %{THE_REQUEST} \s/+profile(?:\.php)?\?(eid)=(\d+)\s [NC]
     RewriteRule ^ /%1/%2? [R=301,L]

     # internally rewrite /eid/1 to /profile.php?eid=1
     RewriteRule ^(eid)/(\d+)$ profile.php?$1=$2 [L,QSA,NC]

     # redirect /dept?did=1 to /did/1
     RewriteCond %{THE_REQUEST} \s/+dept(?:\.php)?\?(did)=(\d+)\s [NC]
    RewriteRule ^ /%1/%2? [R=301,L]

    # internally rewrite /did/1 to /dept.php?did=1
     RewriteRule ^(did)/(\d+)$ dept.php?$1=$2 [L,QSA,NC]

     # redirect /job-details?job=1 to /job/1
      RewriteCond %{THE_REQUEST} \s/+job-details(?:\.php)?\?(job)=(\d+)\s [NC]
     RewriteRule ^ /%1/%2? [R=301,L]

     # internally rewrite /job/1 to /job-details.php?job=1
     RewriteRule ^(job)/(\d+)$ job-details.php?$1=$2 [L,QSA,NC]

      RewriteCond %{THE_REQUEST} \s/+enterprise\.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 ^(.+)$ enterprise.php?url=$1 [L,QSA]

任何人都可以建议实现这一目标吗?do = about& w = me comon无处不在,只需要在页面后像/ about / me那样做。

1 个答案:

答案 0 :(得分:1)

由于有如此多的规则,这种规则很难维持,但现在是:

ErrorDocument 403 /www.domain.com/error404.php
Options All -Indexes
RewriteEngine On
RewriteBase /

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

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

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

# redirect /profile?eid=1 to /eid/1
RewriteCond %{THE_REQUEST} \s/+profile(?:\.php)?\?(eid)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

# internally rewrite /eid/1 to /profile.php?eid=1
RewriteRule ^(eid)/(\d+)$ profile.php?$1=$2 [L,QSA,NC]

# redirect /dept?did=1 to /did/1
RewriteCond %{THE_REQUEST} \s/+dept(?:\.php)?\?(did)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

# internally rewrite /did/1 to /dept.php?did=1
RewriteRule ^(did)/(\d+)$ dept.php?$1=$2 [L,QSA,NC]

# redirect /job-details?job=1 to /job/1
RewriteCond %{THE_REQUEST} \s/+job-details(?:\.php)?\?(job)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

# internally rewrite /job/1 to /job-details.php?job=1
RewriteRule ^(job)/(\d+)$ job-details.php?$1=$2 [L,QSA,NC]

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

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

# /dash?do=about&w=me => /dash/about/me
RewriteCond %{THE_REQUEST} \s/+([^?]+)(?:.php)?\?do=([^&\s]+)&w=([^&\s]+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]

RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ $1.php?do=$2&w=$3 [L,QSA]

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

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