Home How to rewrite an url with two query inside to one folder?
Reply: 2

How to rewrite an url with two query inside to one folder?

Robin Published in 2018-01-06 09:08:04Z

I'm facing a problem to transform my actual url


into this one :


I checked if the rewrite engine works well and it's ok so that's my .htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ 
RewriteCond %{QUERY_STRING} ^&pseudo=([a-zA-Z0-9]+)$ 
RewriteRule ^myspace\$  http://website/login/profil.php?id=$1&pseudo=$2  [R=301,L]

So my wish is to redirect the user's space on one common directory. what's the best way do do this ? am i wrong with the query ?

Thanks in advance guys !

This code doesn't work :

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^test\.html$ /profil.php?id=([0-9]+)&pseudo=([a-z]+) [L]

axcl Reply to 2018-01-06 09:35:32Z

Try this .htaccess it will work only when get parameters are in the same order i.e.


RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/login/profil\.php$
RewriteCond %{QUERY_STRING} ^id=(\d+) [NC]
RewriteCond %{QUERY_STRING} &pseudo=(\w+) [NC]
RewriteRule ^login/profil\.php$ /myspace? [L,R=301]
Hetal Chauhan
Hetal Chauhan Reply to 2018-01-06 10:26:39Z

This format works for me. You also try this:

Put this line into your .htaccess file

RewriteRule ^myspace/?$ login/profil.php?id=34&pseudo=robin

And yes, do not forget to set rewrite base in your .htaccess file: below line will set the base url:

RewriteBase /

So, basically you need to put these both lines into your htaccess file

RewriteBase /
RewriteRule ^myspace/?$ login/profil.php?id=34&pseudo=robin

For dynamic id and name, you can use:

RewriteRule ^myspace/([0-9]+)/([A-Za-z0-9._-]+)/?$ login/profil.php?id=$1&pseudo=$2

So, into your profile.php file, you can check parameter values(id and name)by


So, example, you will have to run the url something like,

http://websitename.com/myspace/20/robin/ or http://websitename.com/myspace/25/john/ ... and like wise.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.333079 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO