Php mod_重写无法完全工作

Php mod_重写无法完全工作,php,wordpress,apache,.htaccess,mod-rewrite,Php,Wordpress,Apache,.htaccess,Mod Rewrite,我有一个.htaccess,看起来像这样 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{QUERY_STRING} ^page=([^&]+) [NC,OR] RewriteCond %{QUERY_STRING} &page=([^&]+) [NC

我有一个.htaccess,看起来像这样

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{QUERY_STRING} ^page=([^&]+) [NC,OR]
RewriteCond %{QUERY_STRING} &page=([^&]+) [NC]
RewriteRule ^index\.php$ /%1? [R,NC,L]
</IfModule>
第一个服务器只是测试htaccess文件。 第二台服务器是活动服务器。我正在运行wordpress,我希望index.php?page=asd链接消失,重定向到/asd,但仍然映射到index.php?page=asd

我该怎么做

根据请求,提供第二台服务器的完整htaccess文件

# Attempt to override some php settings, these settings may be helpful on some hosts if your
# default configuration does not meet CMS's minimum requirements, and your host
# has given your account appropriate permissions
php_value upload_max_filesize "10M"
php_value session_save_path "tmp/cache"

#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off

# (this is important, so uncomment if your host permit)
Options -Indexes
ServerSignature Off

Options +FollowSymLinks

# To prevent E_STRICT problems with PHP 5.3+ you can uncomment the following lines
# Note: These settings should only be enabled for production sites!
#php_flag display_startup_errors 0
#php_flag display_errors 0
#php_flag html_errors 0
#php_value docref_root 0
#php_value docref_ext 0

<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms
#RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# but ignore POST requests.
#RewriteCond %{REQUEST_URI} !/$
#RewriteCond %{REQUEST_URI} !\.
#RewriteCond %{REQUEST_METHOD} !POST$
#RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

#RewriteRule ^(.*)$ /$1 [R=301,L]

#RewriteRule ^index\.php/(.*)$ /$1 [R,NC,L]

#RewriteCond %{QUERY_STRING} ^page=([^&]+) [NC,OR]
#RewriteCond %{QUERY_STRING} &page=([^&]+) [NC]
#RewriteRule ^index\.php$ /%1? [R,NC,L]
</IfModule>

<IfModule mod_rewrite.c>

</IfModule>

<IfModule mod_header.c>
# Disable ETags
Header unset ETag
FileEtag None
</IfModule>

<IfModule mod_deflate.c>
# Compress css, plaintext, xml, gif, and images in transport.
AddOutputFilterByType DEFLATE text/css text/plain text/xml image/gif image/jpeg image/png
</IfModule>

<IfModule mod_expires.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
# Set expires tags on various files... so that the browser wont attempt to reload them.
ExpiresActive On
ExpiresDefault "access plus 1 year"
<IfModule mod_header.c>
  # Setting cache control to public allowes proxy servers to cache the items too.
  Header set Cache-Control "public"
</IfModule>
</FilesMatch>
</IfModule>

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

<IfModule mod_headers.c>
# WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf|woff)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>
#尝试覆盖某些php设置,如果您的
#默认配置不符合CMS的最低要求,并且您的主机
#已为您的帐户授予适当的权限
php\u值上传\u最大\u文件大小“10M”
php_值会话_保存_路径“tmp/cache”
#php_标志魔术_引号_gpc关闭
#php_标志寄存器_全局关闭
#php_标志会话。使用_trans_sid关闭
#(这很重要,如果您的主机允许,请取消注释)
选项-索引
服务器签名关闭
选项+FollowSymLinks
#为了防止PHP5.3+出现严格的E_问题,您可以取消注释以下几行
#注意:这些设置只能为生产站点启用!
#php_标志显示_启动_错误0
#php_标志显示_错误0
#php_标志html_错误0
#php_值docref_根0
#php_值docref_ext 0
重新启动发动机
#
#副目录,例如:/cmsms
#重写基/
#301将所有不包含点或尾随斜杠的请求重定向到
#包括尾随斜杠
#但是忽略POST请求。
#重写cond%{REQUEST_URI}/$
#重写条件%{REQUEST\u URI}!\。
#重写cond%{REQUEST_METHOD}!职位$
#重写规则^(.*)%{REQUEST_URI}/[R=301,L]
#以/parent/child的形式重写URL/
#但仅当请求的URL不是文件或目录时才重写
#
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(+)$index.php?页面=$1[QSA]
#重写规则^(.*)$/$1[R=301,L]
#重写规则^index\.php/(.*)$/$1[R,NC,L]
#RewriteCond%{QUERY_STRING}^page=([^&]+)[NC,或]
#RewriteCond%{QUERY_STRING}&page=([^&]+)[NC]
#重写规则^index\.php$/%1?[R,NC,L]
#禁用ETag
标题未设置ETag
FileTag无
#在传输中压缩css、明文、xml、gif和图像。
AddOutputFilterByType DEFLATE text/css text/plain text/xml image/gif image/jpeg image/png
#在各种文件上设置expires标记。。。这样浏览器就不会尝试重新加载它们。
过期于
ExpiresDefault“访问权限加1年”
#将“缓存控制”设置为“公共”也允许代理服务器缓存项目。
标头集缓存控制“公共”
#压缩文本、html、javascript、css、xml:
AddOutputFilterByType泄气文本/普通
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE应用程序/xml
AddOutputFilterByType DEFLATE应用程序/xhtml+xml
AddOutputFilterByType DEFLATE应用程序/rss+xml
AddOutputFilterByType DEFLATE应用程序/javascript
AddOutputFilterByType DEFLATE应用程序/x-javascript
#或者,按扩展名压缩某些文件类型:
SetOutputFilter放气
#周
标题集缓存控制“最大年龄=604800,公共”

使用以下代码更改所有重写规则块:

RewriteEngine On

# redirects /index.php?page=asfd to /asdf
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]

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

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

如果这是WP,可能会有更多的规则。你能出示你的完整的。htaccessI更新了我的原始帖子正在工作。只是一件我忘了提的小事/index.php/asd也在工作。。您是否也可以修复该问题,使其重定向到/asd//编辑:我添加了RewriteRule^index\.php/(.*)$/$1[R,NC]作为最后一行,它可以正常工作。谢谢
RewriteEngine On

# redirects /index.php?page=asfd to /asdf
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]

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

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