homepage Welcome to WebmasterWorld Guest from 23.20.61.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
RewriteCond and RewriteRule problem.
Nice look URL with query
Lukacius



 
Msg#: 4651311 posted 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

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



 
Msg#: 4651311 posted 11:20 am on Mar 5, 2014 (gmt 0)

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



 
Msg#: 4651311 posted 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

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



 
Msg#: 4651311 posted 12:06 pm 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

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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4651311 posted 12:24 pm on Mar 5, 2014 (gmt 0)

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



 
Msg#: 4651311 posted 9:06 am on Mar 11, 2014 (gmt 0)

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

Thx all.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved