htaccess |重写规则

时间:2013-06-06 11:44:55

标签: regex apache .htaccess mod-rewrite

我正在将一个网站从Windows Server迁移到一个Apache,我喜欢在我的新服务器中将一些404 URL重写为正确/等效的URL。

我喜欢做的是使用RexEx进行以下排序:

Redirect 301 /username/search.asp                /newdir/username/
Redirect 301 /username/contact.asp               /newdir/username/
Redirect 301 /username/legalmarketing.asp        /newdir/username/
Redirect 301 /username/home.asp                  /newdir/username/

我尝试使用RewriteRule:

RewriteRule ^/username/(search|contact|legalmarketing|home)\.asp$ /newdir/username/ [R=301,L]

Bat这不起作用。还有什么好主意吗?我做错了吗?

更新#1

我也试过

RewriteRule ^/username/search.asp$   /newdir/useranme/ [R=301,L]
#as well the following
RewriteRule ^username/search.asp$   /newdir/useranme/ [R=301,L]

但仍然没有机会

更新#2

我也尝试了这个教程:http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html并且问题似乎更复杂,因为我从服务器获取了空值。

这是教程代码生成的代码:

Missed These Variables:
Array
(
    [INFO_API_VERSION] => (null)
    [INFO_AUTH_TYPE] => (null)
    [INFO_CONTENT_LENGTH] => (null)
    [INFO_CONTENT_TYPE] => (null)
    [INFO_DOCUMENT_ROOT] => (null)
    [INFO_GATEWAY_INTERFACE] => (null)
    [INFO_HTTPS] => (null)
    [INFO_HTTP_ACCEPT] => (null)
    [INFO_HTTP_ACCEPT_CHARSET] => (null)
    [INFO_HTTP_ACCEPT_ENCODING] => (null)
    [INFO_HTTP_ACCEPT_LANGUAGE] => (null)
    [INFO_HTTP_CACHE_CONTROL] => (null)
    [INFO_HTTP_CONNECTION] => (null)
    [INFO_HTTP_COOKIE] => (null)
    [INFO_HTTP_FORWARDED] => (null)
    [INFO_HTTP_HOST] => (null)
    [INFO_HTTP_KEEP_ALIVE] => (null)
    [INFO_HTTP_MOD_SECURITY_MESSAGE] => (null)
    [INFO_HTTP_PROXY_CONNECTION] => (null)
    [INFO_HTTP_REFERER] => (null)
    [INFO_HTTP_USER_AGENT] => (null)
    [INFO_IS_SUBREQ] => (null)
    [INFO_ORIG_PATH_INFO] => (null)
    [INFO_ORIG_PATH_TRANSLATED] => (null)
    [INFO_ORIG_SCRIPT_FILENAME] => (null)
    [INFO_ORIG_SCRIPT_NAME] => (null)
    [INFO_PATH] => (null)
    [INFO_PATH_INFO] => (null)
    [INFO_PHP_SELF] => (null)
    [INFO_QUERY_STRING] => (null)
    [INFO_REDIRECT_QUERY_STRING] => (null)
    [INFO_REDIRECT_REMOTE_USER] => (null)
    [INFO_REDIRECT_STATUS] => (null)
    [INFO_REDIRECT_URL] => (null)
    [INFO_REMOTE_ADDR] => (null)
    [INFO_REMOTE_HOST] => (null)
    [INFO_REMOTE_IDENT] => (null)
    [INFO_REMOTE_PORT] => (null)
    [INFO_REMOTE_USER] => (null)
    [INFO_REQUEST_FILENAME] => (null)
    [INFO_REQUEST_METHOD] => (null)
    [INFO_REQUEST_TIME] => (null)
    [INFO_REQUEST_URI] => (null)
    [INFO_SCRIPT_FILENAME] => (null)
    [INFO_SCRIPT_GROUP] => (null)
    [INFO_SCRIPT_NAME] => (null)
    [INFO_SCRIPT_URI] => (null)
    [INFO_SCRIPT_URL] => (null)
    [INFO_SCRIPT_USER] => (null)
    [INFO_SERVER_ADDR] => (null)
    [INFO_SERVER_ADMIN] => (null)
    [INFO_SERVER_NAME] => (null)
    [INFO_SERVER_PORT] => (null)
    [INFO_SERVER_PROTOCOL] => (null)
    [INFO_SERVER_SIGNATURE] => (null)
    [INFO_SERVER_SOFTWARE] => (null)
    [INFO_THE_REQUEST] => (null)
    [INFO_TIME] => (null)
    [INFO_TIME_DAY] => (null)
    [INFO_TIME_HOUR] => (null)
    [INFO_TIME_MIN] => (null)
    [INFO_TIME_MON] => (null)
    [INFO_TIME_SEC] => (null)
    [INFO_TIME_WDAY] => (null)
    [INFO_TIME_YEAR] => (null)
    [INFO_TZ] => (null)
    [INFO_UNIQUE_ID] => (null)
)

还有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试以下内容

RewriteRule ^username/search.asp$   http://www.yourdomainname.com/newdir/useranme/ [R=301,L]