tdjfdjdj
tdjfdjdj

Reputation: 2471

htaccess rewrite redirect to non existing page

I am having a bit of trouble with my URL rewrite.

I want to:

  1. rewrite urls with params to slashes

  2. redirect to rewritten urls.

  3. allow for A-Z0-9 directories before test.php in url. right now /test.php only triggers.

example:

 a href="test.php?options=1>Click here</a>

when clicked will redirect to url:

test/options/1  

OR

abc123/test/options/1  (if the link had abc123/test.php)

and this page will open as the actuall test.php

Existing code:

RewriteRule ^test/(.*)$ /test.php?options=$1
RewriteRule  ^test\.php$ /test/options/%1  [L,R=301]

Two problems with above code:

  1. slashes work, but parameter wont go away at end of url. ?options=xx stays
  2. test.php may have directories numbers or letters before it in url. In this case URL Rewrite doesnt trigger.

Upvotes: 0

Views: 134

Answers (1)

unixmiah
unixmiah

Reputation: 3143

If you simply wanted to redirect /test?options={param} to /test/1/ and /test?options={params} to /test you could do this:

RewriteCond %{QUERY_STRING}     ^test=options$     [NC]
RewriteRule ^/test$             /test/options/     [NC,L,R=301]

RewriteCond %{QUERY_STRING}     ^test=options$    [NC]
RewriteRule ^/blog$             /test/          [NC,L,R=301]

Upvotes: 1

Related Questions