RAHUL DAS GUPTA
RAHUL DAS GUPTA

Reputation: 1

Rewrite Query String with .htaccess

I'm trying to do a very simple rewrite of a query string

http://www.example.com/library.php?q=abscessed-tooth

to

http://www.example.com/library/abscessed-tooth

This is the code that I've written in my .htaccess file and it is doing nothing

RewriteEngine On
RewriteRule ^/library/?([^/]*)/?\/http://www.example.com/library.php?q=$1 [L]

Upvotes: 0

Views: 123

Answers (2)

arkascha
arkascha

Reputation: 42885

Maybe likely .htaccess files are not considered in your environment. If in doubt turn on RewriteLogging as it is explained in the excellent documentation of the rewriting module.

Oh, and check the error log, you have a syntax error in the RewriteRule anyway: RewriteRule takes 2 arguments plus flags, your rule has only a single argument:

RewriteEngine On
RewriteRule ^library/([^/]*) http://www.example.com/library.php?q=$1 [L]

Upvotes: 1

Moseleyi
Moseleyi

Reputation: 2859

You need dollar sign in the end of "left" part not question mark:

^/library/([^/]*)/$ http://www.example.com/library.php?q=$1 [L]

Also do you need the question mark between / and ( ? It doesn't look like lookahead or lookbehind?

Try without wrapping slashes as well

^library/([^/]*)$ http://www.example.com/library.php?q=$1 [L]

Upvotes: 0

Related Questions