Grow your CSS skills. Land your dream job.

removed question mark

  • # March 14, 2013 at 3:35 pm

    Hie guys, I’ve an issue with the mod_rewrite, is about remove the whole example.com/index.php?page=’home’ to example.com/page/home i tried but stil with no success but only the index.php is gone there is my .htaccess look like:

    #
    Options +FollowSymLinks
    RewriteEngine On
    #

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?page=$1

    RewriteRule ^(([^/]+/)*)index.php?$ http://localhost/hector/$1 [R=301,L]

    #

    # March 14, 2013 at 6:18 pm

    Disclaimer: I am not good at .htaccess rules. I’m stumbling my way around here. But isn’t this what you want, in a basic sort of way?

    Options +FollowSymLinks
    RewriteEngine On

    RewriteRule ^page/(.*)$ http://localhost/hector/index.php?page=$0 [NC]

    With this, if the user types in “http://localhost/hector/page/cheeseburgers“ the page “http://localhost/hector/index.php?page=cheeseburger“ is requested, but the user sees “http://localhost/hector/page/cheeseburgers“ in their address bar. Still needs a regex to strip trailing slashes.

    From your example, it looks like you’re reversing this, which would cause a 404 error, if I’m not mistaken? *flounders*

    # March 15, 2013 at 7:43 am

    No my friend,
    the url is http://localhost/hector/index.php?page=Home
    after my .htaccess it removed the index.php and becomes this:
    http://localhost/hector/?page=Home the links work fine but what i want was to
    become this link without the question mark and =
    llike this:

    http://localhost/hector/page/Home

    # March 15, 2013 at 12:19 pm

    Aha! We were both considerably off. It’s the “QUERY_STRING“ that should be referenced, not “REQUEST_FILENAME“. This should do the trick:

    Options +FollowSymLinks
    RewriteEngine On

    RewriteCond %{QUERY_STRING} ^(w+)=(w+)$

    RewriteRule ^([a-z]+)/(index.php) $1/%1/%2? [R=301,L]

    Here are a couple of good resources for testing .htaccess rules: http://htaccess.madewithlove.be/ (doesn’t support “%{REQUEST_FILENAME}“) and: http://martinmelin.se/rewrite-rule-tester/

    # March 15, 2013 at 3:17 pm

    thank you for your help but it doesn’t work
    still the same

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".