MOD REWRITE (BASE) on WAMP Server - apache

I have an WAMP webserver with Rewrite module activated.
I have all my projects in:
d:/prj/costumer1/www/ (alias: costumer1)
d:/prj/costumer2/www/ (alias: costumer2)
and so on...
For costumer1 I have an .htaccess-file that works just fine. Looking like this:
RewriteEngine on
RewriteBase /costumer1/
RewriteRule ^([^/\.]+)/?$ index.php?a=$1 [QSA]
RewriteRule ^([^/\.]+)/?/([[a-zA-Z0-9_-]+)$ index.php?a=$1&b=$2 [QSA]
RewriteRule ^([^/\.]+)/?/([[a-zA-Z0-9_-]+)/?/([[a-zA-Z0-9_-]+)$ index.php?a=$1&b=$2&c=$3 [QSA]
Now when I create a src/href-link I now have to use:
/costumer1/search/book/novell (aka: costumer1/?a=search&b=book&c=novell)
instead of
/search/book/novell (aka: costumer1/?a=search&b=book&c=novell)
So in short:
I don't want to write "/costumer1" in front of every link: search

I have done something like this in my root .htaccess
RewriteCond %{HTTP_HOST} ^customer1$ [NC]
RewriteCond %{REQUEST_URI} !^/customer1
RewriteRule ^(.*)$ customer1/$1 [L,NS]
But eventually, I moved away from handling this with .htaccess as it was less scalable, and went on to setting virtual hosts, something like this:
<VirtualHost *:80>
DocumentRoot "D:/htdocs/customer1"
ServerName customer1
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/htdocs/customer2"
ServerName customer2
</VirtualHost>
And for this to work, of course edit your hosts file, to have lines like this:
127.0.0.1 customer1
127.0.0.1 customer2

Related

Apache: Using VirtualHost redirect to URL with RewriteCond applied?

So I have a RewriteCond that turns:
domain.com/view.php?a=1
into:
domain.com/artist/name
I have a shorter domain: dmn.com that I would like to provide shortlinks for artists:
dmn.com/name
How can I get dmn.com/name to redirect to: domain.com/artist/name while keeping the shortlink in tact?
.htaccess:
#rewrite profile requests
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule artist/(.*)$ view.php?a=$1 [QSA,NC,L]
httpd.conf:
<VirtualHost *:80>
DocumentRoot /var/www/html/ // <-- ??? not sure what to put here
ServerName dmn.com
ServerAlias www.dmn.com
</VirtualHost>
Since the directory "/artist" doesn't actually exist (since it's being rewritten), I can't seem to put /var/www/html/artist in the DocumentRoot of the VirtualHost config without Apache spitting back:
Warning: DocumentRoot [/var/www/html/artist] does not exist
I think what you want is not an actual redirection, but another rewrite.
You can't do it with a separate VirtualHost. Well, you can if you point it to the same DocumentRoot and duplicate your rules or load them from a common file, either via .htaccess or a Include directive.
You can also add the short domain name to your main domain ServerAlias
<VirtualHost *:80>
# This should point to your current config
DocumentRoot /var/www/artists_profiles/
ServerName example.com
ServerAlias www.example.com ex.com www.ex.com
</VirtualHost>
Then you add the new rules to the top of the file:
RewriteBase /
RewriteCond %{HTTP_HOST} ex.com
RewriteRule ^(^.*) artist/$1
Then your existing rules should pick up. If you want to avoid the shortened domain from responding to the longer urls you could add a similar RewriteCond to the existing rules:
RewriteCond %{HTTP_HOST} !ex.com

magento site redirecting to http://www.hpslightshop.com/

Today I'm trying to configure the sub-domain in Apache web-server(Centos) using virtual-host.Sub domain pointing is working fine.
error
magneto site redirecting to different site (http://www.xxxx.com/)
Note :-
1.IN core_config_data table.I have changed the data to http://test.xxxx.com/
2.cleared /var/cache and /var/session folders in your magento root
<VirtualHost *.80>
DocumentRoot /var/www/html/
ServerName test.xxxx.com
ErrorLog /var/log/xxxx_error_log
CustomLog /var/log/xxx_access_log
</VirtualHost>
Add the below code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
if you run
select * from core_config_data where path like '%base_url%' is changed or not

mod_rewrite in httpd.conf not working (but does in .htaccess)

I have a very similar setup on 2 different servers (the working one is a Plesk install on Centos 6, the other is pretty plain LAMP setup on Centos 6) and im having an issue with mod_rewrite on the plain LAMP server.
I have compared the httpd.conf (and associated includes) on both servers and both are (for all intents and purposes) the same.
On the plesk server i have the following in my httpd.conf file which redirects http://stats.domain.com to http://www.domain.com/webstat/ and this works a treat;
<VirtualHost *:80>
ServerName stats
ServerAlias stats.*
UseCanonicalName Off
RewriteEngine On
RewriteCond %{HTTP_HOST} stats\.(.*) [NC]
RewriteRule ^.*$ http://www.%1/webstat/ [L,R=301]
</VirtualHost>
On the LAMP server i have the following in my httpd.conf file which is supposed to redirect http://stats.domain.com to http://www.domain.com/awstats/awstats.pl?config=domain.com
<VirtualHost *:80>
ServerName stats
ServerAlias stats.*
UseCanonicalName Off
RewriteEngine On
RewriteCond %{HTTP_HOST} stats\.(.*) [NC]
RewriteRule ^$ http://www.%1/awstats/awstats.pl?config=%1 [L,R=301]
</VirtualHost>
This is not working when in the httpd.conf file though. If i add stats.domain.com as virtualhost with full documentroot, etc and then add the same rewrite to .htaccess within that documentroot the redirect works fine.
If i enable rewrite logging then i can see the .htaccess version being worked through, but nothing from the httpd.conf. I cannot for the life of me work out what is wrong/missing :(
The rewrite rule for your LAMP server is just putting in domain.com.
RewriteCond %{HTTP_HOST} stats\.(.*) [NC]
RewriteRule ^$ http://%1/awstats/awstats.pl?config=%1 [L,R=301]
Your comment above says it should be www, more like the first rule.
RewriteRule ^.*$ http://www.%1/awstats/awstats.pl?config=%1 [L,R=301]

Dynamicly set document root for subdomains using regex

I've setup subdomain wildcard to accept anything subdomian,the main problem is that i use DirectAdmin and i am not able to point subdomain to specific path using DA API
i want to point any subdomian to a folder named as subdomian which is exist in subdirectory
for example sub.domian.com should point to /public_html/subdomains/sub
something like this
<VirtualHost *:80>
VirtualDocumentRoot /public_html/subdomains/%1
</VirtualHost>
this would be my ideal if i set subdomains which content a word like ".x" to point in that path
maybe like
<VirtualHost *.x:80>
VirtualDocumentRoot /public_html/subdomains/%1
</VirtualHost>
sorry if question sounds stupid
looks like this is what you need:
<VirtualHost *:8080>
ServerName localhost
ServerAlias *.localhost
#the %1 is the asterisk value! No regexp supported!
VirtualDocumentRoot /home/%1/project
VirtualScriptAlias /home/%1/project
<Directory /home/*/project/>
#...
</Directory>
</VirtualHost>
This can be done totally using htaccess .
You have to enable wildcard subdomain name *.domain.com and point it to domain.com
Then you can use the following types of rules :
RewriteCond %{HTTP_HOST} !www.domain.com [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC]
RewriteRule ^(.*/) /%1/index.php [PT,L]
You can modify RewriteRule as files for subdomains are stored .
found the answer
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !www\.domain\.com$[NC]
RewriteCond %{HTTP_HOST} ^(.*?)\.domain\.com$
RewriteCond %{REQUEST_URI} !folder/(.*?)/
RewriteRule ^(.*) /folder/%1%{REQUEST_URI} [L]
</IfModule>

Apache Redirect Rule Needed.Thanks!

everyone
I have one problem here.
My site is powered by Mediawiki,
which means, the visitors are supposed to visit links like this:
hxxp://www.example.com/wiki/SOMETHING
I want to redirect the user to the Main Page if he is trying to access something else:
hxxp://www.example.com/NOTwiki/SOMETHING -> hxxp://www.example.com/wiki/Main_Page
and
hxxp://www.example.com/NOTwiki -> hxxp://www.example.com/wiki/Main_Page
And "/wiki" is case sensitive,
which means:
hxxp://www.example.com/WiKi/SOMETHING -> hxxp://www.example.com/wiki/Main_Page
I am using a virtual host like this:
<VirtualHost 12.34.56.78:80>
ServerName example.com
ServerAdmin admin#example.com
ServerAlias www.example.com
DocumentRoot /srv/www/example/public_html/mediawiki/
ErrorLog logs/AP/error_log
</VirtualHost>
I am new on Apache and still learning.
Be specific,Please.
Thanks a lot!
This config should be:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteCond %{REQUEST_URI} ^index.php
RewriteRule .* - [L]
RewriteRule !^wiki(/.*)?$ wiki/Main_Page [R=301,L]
</IfModule>
The RewriteCond/RewriteRule says "If the start of the path is not /wiki, rewrite all URLS to /wiki/Main_Page using a 301 redirect (R=301), and do not process any more rules (L)"