...

View Full Version : Some RewriteRule Help



animedude123
04-02-2009, 01:06 AM
Hey,

So currently I have this as my .htaccess file:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ read.php?link=$1

My goal is to take this page: http://www.mysite.com/hehe

and have it show as: http://www.mysite.com/read.php?link=hehe to the server

My current file doesn't work though. I tried changing


RewriteRule ^(.*)$ read.php?link=$1

to


RewriteRule ^_(.*)$ read.php?link=$1


This works.

Now though the link needs to be http://www.mysite.com/_hehe (which I don't really want).

Can anyone help me get this working the way I want? (Also so when a user does like /index.php it won't try to send it to the server as read.php?link=index.php)

Thanks for any help!

animedude123
04-02-2009, 11:21 PM
Took some work, but I finally got it.

replaced


^(.*)$

with


^([a-zA-Z0-9_-]+)$

Works perfectly now :D

levicki
04-03-2009, 01:10 AM
I am not an expert on RewriteRule, but what you have is not a complete solution.

What you did is only to exclude . (dot) so index.php doesn't match anymore, but if someone enters http://www.mysite.com/index and if you have Multiviews enabled he will still get index.php.

Another thing to consider is what happens if you already have an URL with a query string?

http://www.mysite.com/hehe?what=this

You would normally want to get:

http://www.mysite.com/read.php?link=hehe&what=this

Your current rule will drop the query string but that might not be what you wanted.

opqr112
04-06-2009, 11:37 AM
这是新加的空白文章56,可以在ubb可视化编辑器中,添加和修改文章内容。



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum