只有顶级条件有效,其他人无法重写网址吗? [英] only top condition is working not others for url rewriting?

查看:65
本文介绍了只有顶级条件有效,其他人无法重写网址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用于url重写的htaccess代码. 我在这里有问题.

This is my htaccess code for url-rewriting. I have a problem here.

Options +FollowSymLinks -MultiViews -Indexes

<IfModule mod_rewrite.c>

DirectoryIndex index.php

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 404error.php

RewriteEngine On

RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1

RewriteRule ^([A-Za-z0-9-]+)?$ news.php?url=$1

RewriteRule ^([A-Za-z0-9-]+)?$ social.php?url=$1

</IfModule>

这是具有不同数据的三个页面.当我单击 spcification.php 页面数据时,它将在同一页面上重定向我,但是如果我的代码高于此页面,则它将重定向到news.php.

here are three pages with different data. When I click for spcification.php page data then it will redirect me on same page but if my this code is above from this then it will redirect me to on news.php.

RewriteRule ^([A-Za-z0-9-]+)?$ news.php?url=$1

只有顶级条件起作用,其他条件不起作用.

only top condition work not others.

推荐答案

据我所知,您不能对多个条件使用相同的规则

From what I know you cannot use same rule for multiple conditions like this

RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1

当第一个规则匹配时,它将停止搜索相同条件,而必须使用

When first rule matched it stop searching for same condition, instead you have to use

RewriteRule ^specification/([A-Za-z0-9-]+)?$ specification.php?url=$1 [L]
RewriteRule ^news/([A-Za-z0-9-]+)?$ news.php?url=$1 [L]

您的原始网址看起来像这样domain.com/news/value.

Your original url will look like this domain.com/news/value.

这篇关于只有顶级条件有效,其他人无法重写网址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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