.htaccess网址重写查询字符串 [英] .htaccess url rewrite querystring
问题描述
好的,我在这里阅读和搜索了一些内容,但是找不到我的问题的答案,或者说我太新了,无法进行网址重写,只是无法弄清楚。这是我要完成的工作:
Ok I've read and search some here but haven't found an answer for my question or maybe im too new to url rewrite and just can't figure it out. Here's what I am trying to accomplish:
我有一个表,其中包含频道说明和ID,ID用于了解要显示的内容,所以我有类似的东西在我的网址中
I have a table that holds channels description and ID, the ID is used to know what content to show, so I have something like this in my URL
http://www.mysite.com/page?channel=1
现在我想做的是显示以下内容:
now what I would like to do is to display this:
http://www.mysite.com/page/description
并且仍然能够以某种方式获取该描述的ID以显示适当的内容。希望这是有道理的。我唯一想到的是在页面顶部,执行以下操作:
and still be able to somehow get the id of that description to display the appropriate content. hopefully this makes sense. The only thing that i've thought of is at the top of my page, do a:
select * from channels where description = $_GET['description']
并返回ID,然后使用它。那是唯一的方法吗?还是.htaccess足够好?这样的菜鸟:(
and have that return the id, and then use it. Would that be the only way to go? or is .htaccess good enough? such a noob :(
编辑:这是我现在的htaccess:
this is in my htaccess right now:
AddType x-mapp-php5 .php
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
##This is to redirect just stream page only
RewriteRule ^stream/(.+)/([0-9]+)$ /stream.php?channel=$1
推荐答案
如果要获取ID,则要执行以下操作:
If you want to get ID, you shell do next:
- 启用mod_rewrite apache模块
- 在DocumentRoot目录中创建.htaccess
-
粘贴下一个:
- Enable mod_rewrite the apache module
- Create .htaccess in the DocumentRoot directory
Paste next:
RewriteEngine On
RewriteRule ^([0-9]+)$ /page.php?channel=$1
当您按照URL:
When you follow the URL:
您会从URL获得类似内容:
you get content like from URL:
http://www.mysite.com/page?channel=1
这篇关于.htaccess网址重写查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!