我想完成以下操作(重写不重定向):
searchPage.php?crs_category=variable
,如searchPage.php?crs_category=business
至category/business
或category/business/
案例敏感您也可以直接访问category/name
,这是searchPage的重写
index.php/name
至page/name
个案例。请注意,这是重写而非重定向,我只想使用干净的网址访问index.php/name
。您还可以直接访问page/name
index.php/name
注意:
- 它需要考虑空格,例如,如果用户点击searchPage.php?crs_category=html%20and%css
,它会将网址重写为category/html and css
尝试:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} /searchPage.php\?crs_category=([^\s]+) [NC]
RewriteRule ^category/%1? [NE,NC,R,L]
RewriteRule ^category/([^/]+)/?$ /searchPage.php?crs_category=$1 [QSA,L,NC]
RewriteCond %{THE_REQUEST} /index\.php/(\S+) [NC]
RewriteRule ^ /page/%1 [NE,R,L]
RewriteRule ^page/([^/]+)/?$ index.php/$1 [NC,L]
问题: 由于某种原因,请求不适用于这些行:
RewriteCond %{THE_REQUEST} /searchPage.php\?crs_category=([^\s]+) [NC]
RewriteRule ^category/%1? [NE,NC,R,L]
另外,我不确定是谁考虑了空白区域。如果它的searchPage.php?crs_category=html%20andcss
导致category / html和css忽略间距代码
更新
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
# keep replacing space to hyphen until there is no space use internal rewrite
RewriteRule ^([^\s%20]*)[\s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
# when there is no space make an external redirection
RewriteCond %{ENV:NOSPACE} =1
RewriteRule ^([^\s%20]+)$ $1 [R=301,L]
RewriteCond %{THE_REQUEST} /searchPage\.php\?crs_category=([^&]+?)\s [NC]
RewriteRule ^ category/%1? [NE,R,L]
RewriteCond %{THE_REQUEST} /index\.php/(\S+) [NC]
RewriteRule ^ page/%1 [NE,R,L]
RewriteRule ^category/([^/]+)/?$ searchPage.php?crs_category=$1 [QSA,L,NC]
RewriteRule ^page/([^/]+)/?$ index.php/$1 [NC,L]
答案 0 :(得分:1)
您应该在/
之后index.php
而不是?
匹配RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /searchPage\.php\?crs_category=([^&]+?)\s [NC]
RewriteRule ^ category/%1? [NE,R,L]
RewriteCond %{THE_REQUEST} /index\.php/(\S+) [NC]
RewriteRule ^ page/%1 [NE,R,L]
# keep replacing space to hyphen until there is no space use internal rewrite
RewriteRule ^(\S*)\s+(.*)$ $1-$2 [E=NOSPACE:1,DPI]
# when there is no space make an external redirection
RewriteCond %{ENV:NOSPACE} =1
RewriteRule ^(\S+)$ $1 [NE,R=302,L]
RewriteRule ^category/([^/]+)/?$ searchPage.php?crs_category=$1 [QSA,L,NC]
RewriteRule ^page/([^/]+)/?$ index.php/$1 [NC,L]
:
您可以使用以下规则:
function verifyIP (IPvalue) {
errorString = "";
theName = "IPaddress";
var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipArray = IPvalue.match(ipPattern);
if (IPvalue == "0.0.0.0") {
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
} else if (IPvalue == "255.255.255.255") {
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
} if (ipArray == null) {
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
} else {
for (i = 0; i < 4; i++) {
thisSegment = ipArray[i];
if (thisSegment > 255) {
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
i = 4;
}
if ((i == 0) && (thisSegment > 255)) {
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
i = 4;
}
if (thisSegment.toString() == "*")
errorString = "";
}
}
extensionLength = 3;
if (errorString == "")
alert ("That is a valid IP address.");
else
alert (errorString);
}
}