要改写像网页:
mysite.com/eng/cat
重定向到:
mysite.com/eng?sentence=cat
我做了以下重写规则:
的RewriteCond%{THE_REQUEST} ^ GET / ENG /([^&放大器; S] +)[NC]
重写规则^ ENG / ENG ?一句话=%1? [R = 301,NC,L]
但是当我要求
mysite.com/eng/cat
它重写这样
mysite.com/eng?sentence=cat?
我不知道为什么它把一个问号结尾,我也尝试过
的RewriteCond%{THE_REQUEST} ^ GET / ENG /([^&放大器; S] +)[NC]
重写规则^ ENG / ENG ?一句话=%1 [R = 301,NC,L]
和
的RewriteCond%{THE_REQUEST} ^ GET / ENG /([^&放大器; S] +)[NC]
重写规则^ ENG / ENG ?一句话=%1 ? [R = 301,NC,L]
这不作任何区别。任何帮助吗?
我的htaccess文件:
#使用PHP5.3单php.ini中的默认
AddHandler的应用程序/ x-的httpd-php54s的.php
RewriteEngine叙述上
的RewriteCond%{THE_REQUEST} ^ GET S / + ENG /([^ /&放大器;? S] +)[NC]
重写规则^ ENG?一句话=%1 [R = 302,NC,L,NE]
将AddType应用/ X的httpd - PHP的.htm的.html
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} PHP -f
重写规则^(。*)$ $ 1.PHP
选项-Indexes
ErrorDocument的404 /404.php
ErrorDocument的500 /500.php
< FilesMatch&GT(JPG | JPEG | PNG | | GIF SWF)$。;
页眉设置缓存控制最大年龄= 604800,公开
< / FilesMatch>
解决方案
就在这个规则应该工作:
的RewriteCond%{THE_REQUEST} ^ GET S / + ENG /([^ /&放大器;? S] +)[NC]
重写规则^ ENG?一句话=%1 [R = 302,NC,L,NE]
请确保在不同的浏览器进行测试,以避免301缓存陷阱。
一旦你验证它是否工作正常,更换 R = 302
到 R = 301
。避免使用 R = 301
(永久重定向),而测试你的mod_rewrite规则。
建议htaccess文件:
#使用PHP5.3单php.ini中的默认
AddHandler的应用程序/ x-的httpd-php54s的.php
将AddType应用/ X的httpd - PHP的.htm的.html
选项-Indexes -MultiViews
ErrorDocument的404 /404.php
ErrorDocument的500 /500.php
RewriteEngine叙述上
的RewriteCond%{THE_REQUEST} ^ GET S / + ENG /([^ /&放大器;? S] +)[NC]
重写规则^ / ENG?一句话=%1 [R = 302,NC,L,NE]
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} PHP -f
重写规则^(。*)$ $ 1.PHP [L]
< FilesMatch&GT(JPG | JPEG | PNG | | GIF SWF)$。;
页眉设置缓存控制最大年龄= 604800,公开
< / FilesMatch>
to rewrite pages like:
mysite.com/eng/cat
to redirect to:
mysite.com/eng?sentence=cat
I made the following rewrite rule:
RewriteCond %{THE_REQUEST} ^GET /eng/([^&s]+) [NC]
RewriteRule ^eng/ eng?sentence=%1? [R=301,NC,L]
but when i request
mysite.com/eng/cat
it rewrites like this
mysite.com/eng?sentence=cat?
i dont know why it puts a question mark at the end, i also tried
RewriteCond %{THE_REQUEST} ^GET /eng/([^&s]+) [NC]
RewriteRule ^eng/ eng?sentence=%1 [R=301,NC,L]
and
RewriteCond %{THE_REQUEST} ^GET /eng/([^&s]+) [NC]
RewriteRule ^eng/ eng?sentence=%1? [R=301,NC,L]
which dont make any difference. any help?
my htaccess file:
# Use PHP5.3 Single php.ini as default
AddHandler application/x-httpd-php54s .php
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GETs/+eng/([^/?&s]+) [NC]
RewriteRule ^ eng?sentence=%1 [R=302,NC,L,NE]
AddType application/x-httpd-php .htm .html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
Options -Indexes
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
<FilesMatch ".(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
解决方案
Just this rule should work:
RewriteCond %{THE_REQUEST} ^GETs/+eng/([^/?&s]+) [NC]
RewriteRule ^ eng?sentence=%1 [R=302,NC,L,NE]
Make sure to test in a different browser to avoid 301 caching pitfall.
Once you verify it is working fine, replace R=302
to R=301
. Avoid using R=301
(Permanent Redirect) while testing your mod_rewrite rules.
Suggested htaccess file:
# Use PHP5.3 Single php.ini as default
AddHandler application/x-httpd-php54s .php
AddType application/x-httpd-php .htm .html
Options -Indexes -MultiViews
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GETs/+eng/([^/?&s]+) [NC]
RewriteRule ^ /eng?sentence=%1 [R=302,NC,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
<FilesMatch ".(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>