Mobile app version of vmapp.org
Login or Join
Holmes151

: URL rewrite issue with cakephp I am using cakephp framework 2.2.2 I want to create personalize URL for user if user enter username=pragnesh then they can access my site like http://pragnesh.mylocalhost.com

@Holmes151

Posted in: #Htaccess #ModRewrite #UrlRewriting

I am using cakephp framework 2.2.2

I want to create personalize URL for user if user enter username=pragnesh
then they can access my site like pragnesh.mylocalhost.com same as in blinksale.com



My URL mylocalhost.com/test/users/front_home
I want to access it as test.mylocalhost.com/users/front_home
My URL: mylocalhost.com/test/setting/pages can be access as : test.mylocalhost.com/setting/pages
any URL: mylocalhost.com/test/xxxxx/xxxxx can be access as : test.mylocalhost.com/xxxxx/xxxxx


OR



URL mylocalhost.com/users/front_home?site=test
I want to access it as test.mylocalhost.com/users/front_home
My URL: mylocalhost.com/setting/pages?site=test can be access as : test.mylocalhost.com/setting/pages
any URL: mylocalhost.com/xxxxx/xxxxx?site=test can be access as : test.mylocalhost.com/xxxxx/xxxxx


My question may be duplicate of stackoverflow.com/questions/20328636/my-cakephp-2-2-site-not-working-on-subdomain but there is no answer posted

I have tried below code in appwebroot.htaccess
stackoverflow.com/questions/5649890/htaccess-subdomai-part-2
RewriteCond %{QUERY_STRING} !^([^&]*&)*site=[^&]+
RewriteCond %{HTTP_HOST} !^www.mylocalhost.com
RewriteCond %{HTTP_HOST} ([a-zA-Z0-9]+).mylocalhost.com
RewriteRule ^([^.]*).php$ /.php?user=%1 [QSA,L,R]

stackoverflow.com/questions/25938781/url-rewrite-for-subdomain
# capture first part of host name
RewriteCond %{HTTP_HOST} ^([^.]+).mylocalhost.com$ [NC]
# make sure site= query parameter isn't there
RewriteCond %{QUERY_STRING} !(^|&)site= [NC]
# rewrite to current URI?site=backererence #1 from host name
RewriteRule ^ %{REQUEST_URI}?site=%1 [L,QSA]


but both not working for me.

my root .htaccss file is

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/ [L]
</IfModule>


app.htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/ [L]
</IfModule>


appwebroot.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>


Virtual Host in httpd.conf

<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/bsale"
ServerName mylocalhost.com
ServerAlias *.mylocalhost.com
<Directory "C:/xampp/htdocs/bsale">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


HOST FILE

127.0.0.1 mylocalhost.com
127.0.0.1 *.mylocalhost.com

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Holmes151

1 Comments

Sorted by latest first Latest Oldest Best

 

@Berumen354

What you are trying to do would be easier at the application level instead of the .hhtaccess level. What you could do is create a single application hosted on the server and each user has a dns record pointed to that application...

eg:
application is hosted on server 1.1.1.1

DNS config is...

app-server IN A 1.1.1.1
user1 IN CNAME app-server.domain.com
user2 IN CNAME app-server.domain.com
user2 IN CNAME app-server.domain.com


What this would do is point all the DNS records to your application and then in your application you simply detect the domain name using whatever native function in your chosen language returns the domain name and then your application handles it as required. This is how most systems are setup that you are talking about andd it minimises configuration requirements as you only need to add a new DNS record each time a new user is created instead of needing to add a new DNS record as well as a new vhost configuration only to host a htaccess file. In addition URL rewrites in apache don't work cross domain and will instead act as a redirect instead of a rewrite.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme