1

i'm looking for a htaccess rule that can do this:

Original URL: ?til=main Replace to: /main

and if this is the scenario:

Original URL: /index.php?til=main or ?til=main Redirect to: /main

Till now i only have this code:

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?til=$1 [L,QSA] 

It loads /main but behind it loads /index.php?til=main

0

2 Answers 2

2

This should work:

RewriteEngine On RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?til=(.*)\ HTTP [OR] RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?til=(.*)\ HTTP RewriteRule ^ /%2? [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?til=$1 [L] 

It should redirect index.php?til=main and ?til=main to /main

Sign up to request clarification or add additional context in comments.

3 Comments

how can i replace til=main for something like til=%1 ??
yep it works! ... quick question is there any problem if i use it like this: RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)?til=([^&\ ]+)\ HTTP RewriteRule ^ /folder/%2? [R=301,L] it seems to work fine with both index.php?til=xxxx and ?til=xxxx
@Ered (.*) It matches any character (except line breaks) which appears zero or more time on first capturing group (which you can refer with $1). While the latter ([^&\ ]+) matches any character except &, \ and spaces with one or more time on second capturing group which referred with $2.
2

Try:

RewriteEngine On RewriteCond %{THE_REQUEST} \ /+(?:index\.php|)\?til=([^&\ ]+) RewriteRule ^ /%1? [L,R] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ /index.php?til=$1 [L,QSA] 

1 Comment

it's not redirecting if i go to index.php?til=main or ?til=main

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.