darki73
darki73

Reputation: 1127

htaccess rewrite virtual folder

im trying to create website, and i need to rewrite php file switch cases to virtual directories.

Im trying to make url of type http://localhost/en/dashboard/mailbox/send/username

to work, and its working with the following code

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC]
## Rewrite Rules
RewriteRule ^/?$ /%1/%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/?$ /index.php?language=$1 [L,NC,QSA]

RewriteRule ^account/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(account)(?:/([^/]+)(?:/([^/]+))?)?/?$ account.php?language=$1&action=$3 [L,NC]

RewriteRule ^dashboard/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))(?:/([^/]+))?)?/?$ /$2.php?language=$1&type=$3&subtype=$4&lasttype=$5 [L,NC,QSA]

However, from now i cannot access http://localhost/en/dashboard/mailbox/ itself

Can someone help me to solve this problem?
Im not into this htaccess thing at all, but i did so far all i could (i think so)

Upvotes: 0

Views: 132

Answers (1)

darki73
darki73

Reputation: 1127

Thanks to @hjpotter92, this problem was solved.

I missed one question mark, so thats why this code was kind of broken.
Here is correct string:

^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$

All i missed is
^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$

And here is fully correct code

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteCond %{HTTP:Accept-Language} ^([a-z]{2})- [NC]
## Rewrite Rules
RewriteRule ^/?$ /%1/%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/?$ /index.php?language=$1 [L,NC,QSA]

RewriteRule ^account/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(account)(?:/([^/]+)(?:/([^/]+))?)?/?$ account.php?language=$1&action=$3 [L,NC]

RewriteRule ^dashboard/?$ /%1%{REQUEST_URI} [L,NC,R]
RewriteRule ^([a-z]{2})/(dashboard)(?:/([^/]+)(?:/([^/]+))?(?:/([^/]+))?)?/?$ /$2.php?language=$1&type=$3&subtype=$4&lasttype=$5 [L,NC,QSA]

Upvotes: 1

Related Questions