Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Some RewriteRule Help

    Hey,

    So currently I have this as my .htaccess file:

    Code:
    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

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

    Code:
    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!

  • #2
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Took some work, but I finally got it.

    replaced

    Code:
    ^(.*)$
    with

    Code:
    ^([a-zA-Z0-9_-]+)$
    Works perfectly now

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    21
    Thanks
    3
    Thanked 2 Times in 2 Posts
    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.
    Last edited by levicki; 04-03-2009 at 01:14 AM.

  • #4
    Banned
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    新加的空白文章56

    这是新加的空白文章56,可以在ubb可视化编辑器中,添加和修改文章内容。


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •