htaccess的重写条件不工作 [英] htaccess rewrite condition not working

查看:140
本文介绍了htaccess的重写条件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在我的网站的网址。我刚刚重写URL从

  http://www.website.com/index.php?url=some-text
 

  http://www.website.com/some-text
 

有关此我用下面的$ C $的.htaccess了C

 选项+ SymLinksIfOwnerMatch
RewriteEngine叙述上

的RewriteBase /

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-l
重写规则^(。*)$的index.php?URL = $ 1 [L,QSA]
 


现在,我想再添变数页号的URL。

  http://www.website.com/index.php?url=some-text&page=1
 

我要重写它像

  http://www.website.com/some-text/1/
和
http://www.website.com/some-text/1
 

我曾尝试以下code,但由于某种原因,它不工作,它显示我的服务器错误。

 的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-l
重写规则^ / $的index.php 1 URL = $&AMP(*)(*);?页= $ 2 [L,QSA]
1重写规则^ / / $的index.php URL = $&AMP(*)(*);?页= $ 2 [L,QSA]
 

解决方案

您不需要2个新的规则。只要一有可选的 / 就足够了。你完全code:

 选项+ SymLinksIfOwnerMatch -MultiViews
RewriteEngine叙述上

的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-l
?重写规则^([^ /] +)/([^ /] +)/ $的index.php 1 URL = $&放大器;页= $ 2 [L,QSA]

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-l
重写规则^([^ /] +)/ $的index.php?URL = $ 1 [L,QSA]
 

在新的code另一个问题是,的RewriteCond 没有得到应用的最后重写规则,因为这些适用于第二天重写规则只。

I am working on URL of my website. I have just rewrite the URL From

http://www.website.com/index.php?url=some-text

to

http://www.website.com/some-text

For this I'm using following code of .htaccess

Options +SymLinksIfOwnerMatch
RewriteEngine on

RewriteBase /

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


Now, I want to add another variable page number in URL.

http://www.website.com/index.php?url=some-text&page=1

I want to rewrite it like

http://www.website.com/some-text/1/
AND
http://www.website.com/some-text/1

I have tried following code but some reason it is not working, it showing me server error.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/(.*)$ index.php?url=$1&page=$2 [L,QSA]
RewriteRule ^(.*)/(.*)/$ index.php?url=$1&page=$2 [L,QSA]

解决方案

You don't need 2 new rules. Just one with optional / will be enough. Your complete code:

Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine on

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

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

Another problem in your new code is that RewriteCond are not getting applied for last RewriteRule since these are applicable to very next RewriteRule only.

这篇关于htaccess的重写条件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆