|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Can I use htaccess to redirect url such as :
URL to URL ? |
|
#2
|
|||
|
|||
|
# http://www.mydomain.com/.htaccess
RewriteEngine on # If you have access to httpd.conf, enable this line (you can't use RewriteMap in .htaccess) # If that's the case, of course, copy all lines here to within <Directory "/path/to/docroot"> # RewriteMap lc int:tolower # Do not redirect if server_name doesn't contain .mydomain.com, use this to work with vhost RewriteCond %{SERVER_NAME} !\.mydomain\.com$ [NC] RewriteRule ^(.+) - [L] # Do not redirect if server_name is already www.mydomain.com # Say a request of http://www.mydomain.com/username/blah.html, then no redirection is needed RewriteCond %{SERVER_NAME} ^www\.mydomain\.com$ [NC] RewriteRule ^(.+) - [L] # Else, if server_name is anything.mydomain.com RewriteCond %{SERVER_NAME} ^[^.]+\.mydomain\.com$ [NC] # Take the server_name env to the next rule RewriteRule ^(.+) %{SERVER_NAME}=$1 [C] # If RewriteMap above is enabled, comment out the following line # What this line does is to map http://USERNAME.mydomain.com/ to http://www.mydomain.com/username/ # That's converting Uppercase Username to lowercase # RewriteRule ^(.*)=(.*) ${lc:$1}$2 [C] # ^([^.+) is the username # (.*) is the / or anything requested, this is also called request_uri # $1 is the value of username # $2 is the value of request_uri including the slash / RewriteRule ^([^.]+)\.mydomain\.com(.*) http://www.mydomain.com/$1$2 [R,L] Once again, any codes I post here is untested (just wrote this up from scratch), so please followup this thread whether it works for you or not. |
|
#3
|
|||
|
|||
|
Dear freebsd,
I added the above lines to my httpds.conf, and now it looks like this : ( offcourse i changed the mydomain with my domain name), <Directory "/usr/local/plesk/apache/vhosts"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all RewriteEngine on RewriteCond %{SERVER_NAME} !\.mydomain\.com$ [NC] RewriteRule ^(.+) - [L] RewriteCond %{SERVER_NAME} ^www\.mydomain\.com$ [NC] RewriteRule ^(.+) - [L] RewriteCond %{SERVER_NAME} ^[^.]+\.mydomain\.com$ [NC] RewriteRule ^(.+) %{SERVER_NAME}=$1 [C] RewriteRule ^([^.]+)\.mydomain\.com(.*) URL$1$2 [R,L] </Directory> but i doesn't work as i expected. Could you tell me what possibly be the problem? Thank You. Vera. |
|
#4
|
|||
|
|||
|
1) As I said, put those with <Directory "/path/to/docroot">. Are you sure /usr/local/plesk/apache/vhosts is your docroot? Check your httpd.conf and find the line DocumentRoot blahblahblah. The blahblahblah is the path of your docroot.
2) Say your docroot (DocumentRoot is /usr/local/plesk/apache, there must not be a subdir at /usr/local/plesk/apache/no_subdir_here/username Since you haven't provided any details of the problem, I suggest you to try to solve the problem yourself by adding: RewriteEngine on RewriteLog "/var/log/rewrite.log" # add this line, create this file manually before restarting apache RewriteLogLevel 9 # add this line RewriteCond %{SERVER_NAME} !\.mydomain\.com$ [NC] .. .. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > htaccess to redirect url |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|