我已经尝试在这里阅读花药问题,但它们对我不起作用。
今天我的.htaccess是这样的
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Ignore sitemap folder
RewriteCond %{REQUEST_URI} !^/myapps/.*$
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
Redirect /acompanhantes h t t p://mysite.com/members?profile_type=4&displayname=&location=&within=50&lat=0&long=0&order=az&show=&1_4_9_alias_gender=&1_4_10_alias_birthdate%5Bmin%5D=&1_4_10_alias_birthdate%5Bmax%5D=&1_1_5_alias_gender=&1_1_6_alias_birthdate%5Bmin%5D=&$
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
如您所见,我将长 url 重定向到 mysite.com/acompanhte
所以,我不想重定向。我想重写。有可能的?怎么办?
最佳答案
一些事情:
重写条件必须链接到规则,因此它会应用于紧随其后的重写规则。顶部的条件似乎没有执行任何操作,因为它已应用于 index.php 规则。
Redirect
指令是 mod_alias 的一部分,其工作方式如下:Redirect A B
,其中 A 是请求的 URL,< strong>B 是重定向TO 的地方。这意味着您必须在浏览器中键入 A URL,然后它告诉浏览器将位置更改到B。此外,(来自 #2)这意味着为了使重定向执行任何有用的操作,您必须能够在浏览器中键入 B url 并让它返回您的内容重新期待(而不是类似错误的东西)。
由于
Redirect
是mod_alias,重写规则是mod_rewrite,两个模块会互相干扰,处理请求两次,所以这里只需要坚持使用mod_rewrite,使用R
标志。
也许你想要这样的东西?
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+members?profile_type=4&displayname=&location=&within=50&lat=0&long=0&order=az&show=&1_4_9_alias_gender=&1_4_10_alias_birthdate%5Bmin%5D=&1_4_10_alias_birthdate%5Bmax%5D=&1_1_5_alias_gender=&1_1_6_alias_birthdate%5Bmin%5D=
RewriteRule ^ /acompanhantes [L,R]
# Ignore sitemap folder (passthrough these requests)
RewriteRule ^myapps/ - [L]
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
关于linux - 用 .htaccess 重写长 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33266210/