Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite help

Minor URL change..

         

patrick89

5:57 pm on Dec 22, 2007 (gmt 0)

10+ Year Member



Hi,

I'm trying to convert URLs from:

www.mysite.com/folder/index.php?/categories

TO:

www.mysite.com/folder/categories

(ie, just remove the "index.php?" part)

It seems so simple, but I've been struggling with this one for weeks!

If anyone could help, I'd really appreciate it. :)

jdMorgan

6:14 pm on Dec 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best effort code as a basis for discussion.

Thanks,
Jim

patrick89

6:23 pm on Dec 22, 2007 (gmt 0)

10+ Year Member



Hi jdMorgan,

Thanks for the reply, here's one of the versions I tried with no luck:

Options +FollowSymlinks
Options +Indexes
RewriteEngine on
RewriteBase /

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

[edited by: jdMorgan at 6:37 pm (utc) on Dec. 22, 2007]
[edit reason] example.com [/edit]

jdMorgan

6:38 pm on Dec 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings --everything after a question mark-- are separate and distinct from a URL; A query string is data attached to a URL to be passed to the resource at that URL. In other words, a query string does not specify any part of a "Resource Location" and so is not part of a URL.

For this reason, query strings are handled separately in mod_rewrite; You can use a RewriteCond to test and extract queery string data:


Options +FollowSymlinks +Indexes
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^/(.+)$
RewriteRule ^folder/index\.php$ http://www.example.com/folder/%1? [R=301,L]

Note also that the Options were combined and that the redundant (default-value) RewriteBase directive was removed. The trailing "?" on the substitution URL is a mod_rewrie token required to clear the originally-requested query string, and will not be sent to the client.

Jim