3

I managed to put together .htaccess like this and it is working fine

RewriteRule ^$ /splash [L,R=301]        
RewriteCond %{HTTP_HOST}  ^example.com
RewriteRule (.*) http://www.examle.com/$1 [R=301,QSA,L]
RewriteRule ^([A-Za-z0-9-]+)?$ /index.php?cat=$1 [L]

This redirects things like example.com/one to http://www.example.com/index.php?cat=one

However, I would like to add more functionality for my current project so that multiple variables get parsed. So for example:

example.com/category-one?another_variable=some_data&even_more=more_data, etc... 

get parsed to

http://www.example.com/index.php?cat=category-one&another_variable=some_data&even_more=more_data

Also, is solution like this seo-friendly?

2 Answers 2

1

Add QSA flag in last rule:

RewriteRule ^$ /splash [L,R=301]

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteRule ^([a-z0-9-]+)/?$ /index.php?cat=$1 [L,NC,QSA]
  • QSA (Query String Append) flag preserves existing query parameters while adding a new one.
Sign up to request clarification or add additional context in comments.

3 Comments

Seems like it is working for first two variables (cat and second one), but if I add one more, then content of second variable is filled like some_data?even_more=more_data
QSA flag will with any number of query parameters. Provide an example of URL for which it didn't work.
This URL is not correct: autobazar-ns.cz/garance-kvality?car=abcd?car2=aaa since there are 2 ? in the URI
0

try this RewriteRule ^mydir/([0-9]+)/(.*)$ myfile.php?var1=$1&var2=$2 [NC,L]

Comments

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.