/    Sign up×
Community /Pin to ProfileBookmark

mod_rewrite problem

Hello, I want to make redirect from this page [url]http://domain.com/search/?test=blablabla[/url] to [url]http://domain.com/search/blablabla/[/url]
I can’t do this, thats my RewriteRule:

[code=php]RewriteRule ^search/?test=(.+)$ search/$1/ [R] [/code]

but it doesn’t work. I can’t find a mistake, help me please.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@DariaSep 27.2011 — Just some brainstorming here...

are you trying to actually redirect to the different location (i.e. do you actually have the search/blablabla/ folder - probably not ) , or to simply rewrite the url string?


"it does not work" meaning you still see the http://domain.com/search/?test=blablabla in the url bar and page content resolves properly, or is there an error message of any sort?

Do you have your RewriteEngine turned on?
[code=html]RewriteEngine on[/code]
in you .htaccess file?

Does your host allow mod_rewrite?

If yes (and given that there are no file extensions in your sample - if it mimics your actual links - , then probably yes it is), is it the only rewrite pattern that does not rewrite properly?
Copy linkTweet thisAlerts:
@DariaSep 27.2011 — I hope I didn't make mistakes here, but I think that's what you need:

RewriteEngine on

RewriteRule ^search/([^/.]+)/?$ search/?test=$1 [L]
Copy linkTweet thisAlerts:
@ijsauthorSep 27.2011 — Thanks for reply.

I'm trying to rewrite url string.

I'm still see the http://domain.com/search/?test=blablabla in the url bar and page content resolves properly.

Yes, RewriteEngine turned on.

Yes, my host allow mod_rewrite.

That's only one pattern that doesn't work.

no, that is not what i'm looking for
[code=php]RewriteEngine on
RewriteRule ^search/([^/.]+)/?$ search/?test=$1 [L]
[/code]

that pattern provides that url http://domain.com/search/blablabla/ will actually work as that url http://domain.com/search/?test=blablabla and i need a page redirect (reload) on from this url http://domain.com/search/?test=blablabla to that url http://domain.com/search/blablabla/
Copy linkTweet thisAlerts:
@DariaSep 28.2011 — Can you please provide more detail on purpose of this redirect - on what is it you are actually trying to do, in terms of functionality? Are you using a SEARCH FORM to POST the date and then GETTING the value of $_POST['test'], and redirecting to the url that would be derived by this method (which is - or is it not - an actual directory)? Or are you doing something else entirely?


-------------------------------------------------------
in a meanwhile, here are some great resources:

Apache mod_rewrite: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

When not to use: https://httpd.apache.org/docs/2.3/rewrite/avoid.html
Copy linkTweet thisAlerts:
@ijsauthorSep 28.2011 — I have a form mm like this [code=php]<form action="" method="get">
<input type="search" name="search">
</form>[/code]

after we use this form, to our url will add string like ?search=something

but i don't like url index.php?search=something

i want see this url index/something

i think the problem with "?" symbol, in mod_rewrite,
[code=php]RewriteRule ^index.php?search=(.+)$ index/$1/ [R] [/code]
Copy linkTweet thisAlerts:
@DariaOct 04.2011 — Don't take my word for it, but I am not sure that you can do what you want to do via form with get method... Perhaps someone else would be able to answer that better. Sorry! If I come across (an alternative) solution in the meanwhile, I would let you know.
×

Success!

Help @ijs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...