Welcome to WebmasterWorld Guest from 54.227.110.209

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteCond and RewriteRule problem.

Nice look URL with query

     

Lukacius

10:46 am on Mar 5, 2014 (gmt 0)



Hi,
I want to change the url fom www.example.com/?str=test to www.example.com/test

i write this in .htaccess file but it not work :/

RewriteCond %{REQUEST_URI} ^\/index.php
RewriteCond %{QUERY_STRING} ^\?str=$1
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

any one got some ideas ?

[edited by: phranque at 11:21 am (utc) on Mar 5, 2014]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

phranque

11:20 am on Mar 5, 2014 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Lukacius!


IMPORTANT: Please Use Example.com For Domain Names in Posts [webmasterworld.com]


RewriteCond %{REQUEST_URI} ^\/index.php

- %{REQUEST_URI} contains the path component of the requested URI which didn't begin with '/index.php' in your case, so that won't match.

RewriteCond %{QUERY_STRING} ^\?str=$1

- the query string starts after the first question mark in the URL so %{QUERY_STRING} won't match a string beginning with a literal '?'.

- if you want to reuse the str parameter value in the substitution string of the RewriteRule to follow then you will have to use a pattern with a regular expression describing the parameter value surrounded by grouping parentheses.

RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

- your problem description didn't mention reusing any of the path component in the redirect.
you don't need to capture anything here.
the $1 should be a %1 so you can reuse the str parameter value captured in the preceding RewriteCond after you have fixed it as i described above.

Lukacius

11:51 am on Mar 5, 2014 (gmt 0)



I can get to web by:
www.example.com/?str=test
or
www.example.com/index.php?str=test

all move by index.php :(

lucy24

12:06 pm on Mar 5, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



I can get to web by:
www.example.com/?str=test
or
www.example.com/index.php?str=test

Separate issue. For this you need an index redirect immediately before the domain-name-canonicalization redirect. This has been discussed approximately eighty thousand times over the years, so a quick Forums search should turn up lots of examples to swipe.

Now then...

I want to change the url fom www.example.com/?str=test to www.example.com/test

I'm sure you do, but mod_rewrite can't do it for you. Only you can change an URL.
:: insert witticism about Buddhist sandwich bar here ::

What you want is two things:
first redirect people who request
example.in/index.php?str=test
and/or
example.in/?str.test
to
example.in/test


And then rewrite requests for
/test
to serve content from
/index.php?str=test

--exactly where the content has been all along, but your users do not need to know that.

If people have been using both forms of the URL, the pattern is
^(index\.php)?$

The part that looks at the query string can be as simple or as complicated as you want to make it. It all depends on what else has been going on with your URLs.

g1smd

12:24 pm on Mar 5, 2014 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



mod_rewrite cannot make or change URLs. The vital step when you want a website to use a new URL format is to change the links on the pages to point to the new format URLs. Everything begins with those links being clicked.

Install a redirect, as detailed above, to cater for people following old links from other sites and stored in bookmarks.

Install the rewrite to fetch content from inside the server when a new format URL is requested.

Lukacius

9:06 am on Mar 11, 2014 (gmt 0)



Ok, after all. I change php code to get nice url :).

Thx all.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month