1

How would I change

http://example.com/?sort=top&time=variable

to

http://example.com/top/variable

&time=variable may not always be used.

My current htaccess:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?showcase/(.*?)/?$ /showcase.php?id=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /showcase\.php\?id=([^\&\ ]+)
RewriteRule ^/?showcase\.php$ /showcase/%1? [L,R=301]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

rewrites http://example.com/showcase.php?id=int to http://example.com/showcase/int.

1 Answer 1

1

If the code is in the .htaccess files, use ^ instead of ^/?. For your particular case, you can modify/add to the existing redirection as follows:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(top)(?:/([^/])+)?/?$ /?sort=$1&time=$2 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?sort=(top)(?:&time=([^\s&]+))? [NC]
RewriteRule ^ /%1/%2? [R=301,L]
Sign up to request clarification or add additional context in comments.

1 Comment

That works! Thanks a lot. I honestly can't wrap my head around writing this stuff, it seems too complex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.