Php .htaccess重写规则和重定向
对于域市场,我想重写一些URL并将我的旧页面(在目录中)直接重定向到新页面 对于“重写url”,我使用了以下代码:Php .htaccess重写规则和重定向,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,对于域市场,我想重写一些URL并将我的旧页面(在目录中)直接重定向到新页面 对于“重写url”,我使用了以下代码: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteCond %{REQUEST_URI} !^/(.*\.php)?$ RewriteCond %{REQUEST_URI} !^/(.*\.htm)?$ RewriteCond %{REQUEST_URI} !^/(.*\.html)?$ RewriteCond
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(.*\.php)?$
RewriteCond %{REQUEST_URI} !^/(.*\.htm)?$
RewriteCond %{REQUEST_URI} !^/(.*\.html)?$
RewriteCond %{REQUEST_URI} !^/(.*\.shtml)?$
RewriteCond %{REQUEST_URI} !^/whois/$
RewriteRule ^(.*\.*)$ /details.php?domain=$1 [qsa,l]
RewriteRule ^whois/([^/]*)$ /whoisrequest/whois.php?whois=$1 [L]
例如http://mydomain.com/test.com
url重写类似http://mydomain.com/details.php?domain=test.com
-没问题
问题:但同时,用于重写whois url(http://mydomain.com/whois/test.com
)或重定向旧页面(如http://mydomain.com/domains/123/test.com
)到新的(如http://mydomain.com/test.com)重写到…details.php?domain=…
我应该如何处理这些规则:
- 如果
http://mydomain.com/test.com
,然后重写http://mydomain.com/details.php?domain=test.com
(仅在主站点上,包括“[dot]-它可以像任何东西一样。任何东西)
- 如果
http://mydomain.com/folder1/
或多个文件夹,则“(点)不重要”将不会重写
- 此外,重定向301
http://mydomain.com/domains/123/test.com
至http://mydomain.com/test.com
您有两个问题:
- 您正在第一条规则中匹配非常通用的
*\..*
模式,这将使第二条规则失效
- 您没有使用
RewriteCond%{REQUEST_FILENAME}!-f
来避免对实际文件/目录进行重写
你的规则是这样的:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^whois/([^/]+)/?$ /whoisrequest/whois.php?whois=$1 [L,QSA]
RewriteRule ^([^/]+)/?$ /details.php?domain=$1 [L,QSA]
我想RewriteCond
只会在第一个RewriteRule
中使用。为每个RewriteRule
添加这些。谢谢你的帮助。我会编辑我的文件。非常感谢你anubhava!你的智能代码工作得很好!我如何重定向我的旧页面?实际上我的旧URL也在重写URL。例如,我使用了这个code:'RewriteRule^domains/([a-z0-9]+)/(.*)/?details.php?id=$1[NC,L]'所以,url像现在一样被重写了,我使用域名而不是id作为详细信息页面。我想用我的新htaccess代码将301重定向到。感谢您可以使用此新重定向:RewriteRule^domains/[a-z0-9]+/(.+)/?$/$1[NC,L,R]
感谢您的帮助anubhava。如果您接受,我想通过PayPal向您支付一点费用。感谢您的提议,但我愿意继续为社区中的其他开发人员提供帮助。我通过多次使用各种开放源代码软件而受益,这是我回报社区的方式。