Im trying to rewrite my url from this :
http://www.somedomain.com/User
to
http://www.somedomain.com/somepage.asp?Username=User
Where the =User in URL 2 is the same as the /User in URL 1. It would be great if it doesnt just redirect, but do the change in the background.
Im using Helicon ISAPI_Rewrite ver 3.
Any help would be greatly appreciated.
It seems that to do a somedomain.com/user direction is possible, BUT it will mean that all requests will be send to your redirect, as somedomain.com/user and somedomain.com/page.asp will both be redirected. For this to work you will need to handle the requests to your redirect accordingly.
What I ended up doing, as this is MUCH less work, is to just redirect somedomain.com/user/username to the page I wanted to redirect to. the rule for this, looks like follow:
RewriteEngine Off
AllowOverride none
<VirtualHost somedomain.com>
RewriteEngine on
AllowOverride all
RewriteRule ^/user/(.*) /somepage.asp?UserName=$1
</VirtualHost>
Hope this helps someone.
Related
i am trying to rewrite the url in apache which internally redirect the requests to apache tomacat
Here is my httpd.conf code
<IfModule mod_rewrite.c>
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/myapp/my.html
ProxyPassReverse / http://localhost:8080/myapp/my.html
RewriteEngine on
RewriteRule ^/(.*)/$ http://localhost:8080/myapp/my.html?product=$1 [QSA]
</IfModule>
so basically what i am trying to do is if i enter localhost/myapp then it should redirect me to localhost:8080/myapp/my.html
Next is if i enter the url localhost/myapp/8 it should redirect internally to localhost:8080/myapp/my.html?product=8.
Now the problem is ProxyPass is working absolutely fine. But the rewrite rule is showing 404 error.
If i remove the ProxyPass code then the same rewrite rule works but it shows the modified url in the browser.
So i want to know where should i place RewriteRule to make it work with ProxyPass and y the rewrite rule is showing the modified urls?
You need to add the [P] flag to the RewriteRule. This causes the RewriteRule to 'proxy' the same way your ProxyPass directive does. At the moment your rule doesn't make any sense. Alternatively you could do something like:
RewriteRule ^/(.*)/$ /myapp/my.html?product=$1 [QSA,PT]
Which should cause the URL to be rewritten and then passed through (this happens because of the PT flag) to any remaining modules that need to process the URI path, in this case the proxy module.
FYI the terminology is wrong, when you say if i enter localhost/myapp then it should redirect me to localhost:8080/myapp/my.html you really mean if i enter localhost/myapp then it should proxy to localhost:8080/myapp/my.html. A redirect is an external response which cases the browser to request a new URL and the text in the browsers address bar will change.
Mind you, with your current configuration, requesting localhost/ will proxy to localhost:8080/myapp/my.html. So if you can specify which is correct it would help.
I'm trying to set up a 301 redirect from a subdomain to a facebook page. I'm using this below and have uploaded it to the root folder on the server. I've also tried to upload this to the subfolder (example.com/blog), but to no avail...
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog.example.co.uk
RewriteRule ^(.*)$ http://www.facebook.com/example/$1 [R=301,L]
#Deny access to htaccess
Order Allow,Deny
Deny from all
Does anyone have any ideas why this isn't working?
Thanks in advance,
Ash
NOTE:
I've investigated this a little further and forgot to mention that the subdomain is set up on an old version of Drupal. This causes the site to fail when we set up any subdomain.
We can still navigate to the folder that the subdomain uses and the redirect works fine there.
So, the issue seems to be with drupal and subdomains, not the redirect.
Thanks,
Ash
What kind of error are you getting?
This bit of code would deny access to everything, not just .htaccess like it states in the comments...
#Deny access to htaccess
Order Allow,Deny
Deny from all
I have the following:
# Enable Redirects
RewriteEngine On
RewriteBase /
Options +FollowSymlinks
Options -Indexes
RewriteRule ^sitemap\.xml$ http://%{HTTP_HOST}/index.php?route=feed/google_sitemap [L,NC]
From what I've read it should just internally rewrite sitemap.xml to http://%{HTTP_HOST}/index.php?route=feed/google_sitemap and not do any redirecting (i.e. changing the URL in the browser), but it is doing and I don't want that.
Can someone point out why please?
I've tried removing the L flag, thinking maybe it's to do with the characters in the URL?
Actually, if I'm not mistaken, mod_rewrite redirects upon getting served with a http-link. What happens if you remove http://%{HTTP_HOST}/? Try it out, and let us know what happens!
I took a look around at other mod_rewrite questions and couldnt come up with an answer, so if anyone would point me to one that I may be duplicating I would appreciate it.
Anyways my question is: Why is my mod rewrite not working? I followed like 3 tutorials and spent a while reading forums and previous questions on this site, and couldnt get any of them to work. Ive tried doing it through my vhosts.conf file (I think its also known as the httpd.conf on some installations of linux) and through a .htaccess
Here is my .htaccess filed code
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^/article/([0-9]+)$ article.php?art_id=$1 [NC,L]
Here is the link im trying to get working: mysite.com/article?art_id=$1
To be honest I only have a slight clue as to how mod_rewrite works.
I have mod_rewrite installed (I don't manage the server, but the company I work for also has hosting services, thats how I have access to the vhosts.conf but I did not set the server up, and as far as I know the guy doing it is pro and set it up right)
I put this in to see if I could get it to work and it redirected me to my home page (I think that means its working)
# Options +FollowSymLinks
RewriteEngine on
RewriteRule ^fakepage\.html$ http://yoursite.com/ [R,L]
At least as far as your .htaccess file goes, using the rule you have will not work because the input to the RewriteRule will never have an initial forward slash on it. The rule should instead look more like this:
RewriteRule ^article/([0-9]+)$ article.php?art_id=$1 [NC,L]
However, what you have should have worked when you tried it in a virtual host (assuming you restarted the server), so I'm not sure if this is the actual issue. In what way is the rewrite not working? Are you getting 404 errors instead of being redirected to the file you were expecting?
Tim is correct about the slash at the beginning of your RewriteRule.
When trying to figure out Rewrites, it can be helpful to turn on logging:
RewriteLog "/var/www/mysite.com/rewrite.log"
RewriteLogLevel 9
My problem is that i have a functioning subdomain (sub.mydomain.com). sub is loaded in mydomain.com/sub.
What i would like to do is to redirect all requests to sub.mydomain.com to mydomain.com.
Somehow it seems that when im the subdomain i cannot access the rootfolder (main domain). I can get it working with from mydomain.com/sub to mydomain.com. But not from the subdomain.
Currently im using:
RewriteEngine on
RewriteRule ^(.*)/?$ /home/web/webuser/$1 [L]
When accessing sub.mydomain.com i get a 500 Internal Server Error.
Is there a restriction in accessing the main from a sub? (rights wise)
Or maybe another way of getting to main, perhaps something like (../$1)
Thanks
EDIT:
I only have access to .htaccess. So DocumentRoot cannot AFAIK be used in .htaccess file.
What about symlinks? I dont really know what it does, but i assume that it links two locations? The only code i found for that enables symlinks (Options +FollowSymlinks) - but this line doesnt say anything about what to link (perhaps im all wrong)
Btw. thanks for input so far !
I must admit that I did not fully understand your question. Do you want to redirect everything from sub.mydomain.com/whatever to mydomain.com/whatever? In that case, the following (put in the config file of your sub.mydomain.com) might work:
RewriteEngine On
RewriteRule ^/(.*)$ http://mydomain.com/$1 [R,L]
It redirects on the client side, meaning that the user will see mydomain.com/sub in the browser.
EDIT: I think I understand your question now. Yes, it's a permissions issue: If the DocumentRoot of your web site is /whatever/sub, then you cannot just access /whatever by adding "/.." to the URL. I hope you understand that this is a good thing. :-) mod_rewrite just changes the URL, so it cannot do that either.
So, to solve your problem, you need to either change the DocumentRoot of sub.mydomain.com or create a symlink that allows you to access the required directory (e.g. /whatever/sub/redir-target -> /whatever). Be careful with the symlink option, though, since it will create valid directories of infinite length on your file system (/whatever/sub/redir-target/sub/redir-target/...) and some scripts cannot cope with that.
EDIT2: Instead of a symlink, you might want to create an alias, e.g., something like this:
Alias /redir-target /home/web/webuser
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/redir-target/.*$
RewriteRule ^/(.*)$ /redir-target/$1
Still, I think the easiest solution is to change the DocumentRoot...
Why not try using a Redirect Directive from mod_alias?
It's difficult to provide a definitive answer without knowing more about your server configuration.
The following might work and is at the very least a decent starting point:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.mydomain\.com
RewriteRule (.*) /$1 [L]
Ideally that would go in your httpd.conf, but might work from a .htaccess file (again, more information about how your subdomains are setup would be helpful).