Mod Rewrite Rule - mod-rewrite

Hi can anybody help me with this rewrite rule.
Basically i have a url http://mydomain.com/http://somewhere.com/photo.gif which i want it to be forwarded to this url: http://mydomain.com/upload.php?url=http://somewhere.com/photo.gif
I have tried the following but it does not work.
RewriteRule ^(.*)$ upload.php?code=$1 [L]

You haven't added a / for upload.php?...
RewriteRule ^(.*)$ /upload.php?code=$1 [L] will work if you can avoid the http:// in http://somewhere.comwhile passing tohttp://mydomain.com/http://somewhere.com/

Related

mod_rewrite with 2 vars works, but URL changes

I got some problem with my htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^contact/ index.php?p=contact [L]
RewriteRule ^imprint/ index.php?p=imprint [L]
RewriteRule ^escort-rates/ index.php?p=escort-rates [L]
RewriteRule ^discretion-reliability/ index.php?p=discretion-reliability [L]
RewriteRule ^(escort-model)/(\.*)/$ index.php?p=$1&l=$2 [L]
If I call www.domain.com/contact/ the URL won't change visible, but is internally directed to index.php?p=contact, it works with the other 3 ones also.
But if I call www.domain.com/escort-model/escortname/ the URL changes visible to the visitor.
The correct page is called, but the URL changes to index.php?p=escort-model&l=escortname
Any hint would be greatly appreciated.
I think it should be (without the parenthesis):
RewriteRule ^escort-model/(.*)/$ index.php?p=$1&l=$2 [L]
instead of:
RewriteRule ^(escort-model)/(.*)/$ index.php?p=$1&l=$2 [L]

Creating SEO friendly URLs with htaccess

when I change the link It shows me an error page. maybe there is a problem with my website what do you think?
There is the url in my website: www.mywebsite.com/picture.php?1
and I want to change it to something like this: www.mywebsite.com/picture/1
here is my .htaccess
RewriteEngine on
rewritecond %{http_host} ^website.com [nc]
rewriterule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]
RewriteRule ^contact\/?$ contact.php [L]
RewriteRule ^terms\/?$ terms.php [L]
**RewriteRule ^picture/(.*)/$ picture.php?$1 [L]**
Please help,
I have no clue what is the problem.
Try adding
<base href="www.mywebsite.com" />
At the top of your page, this might work.
EDIT:
Try using this rewrite rule
RewriteRule picture/(.*)/$ /picture.php?$1 [L, NC]
assuming that the first part of your htaccess works, replace your last line with the following:
RewriteRule ^picture/(.*)$ /picture.php?$1 [NC]

URL Rewrite /foobar/rss to rss.php?username=foobar

I already use URL Rewriting to rewrite /foobar to index.php?username=foobar using:
RewriteRule ^([^/.]+)$ /index.php?username=$1 [QSA,L]
What should I add to also rewrite /foobar/rss to rss.php?username=foobar?
This is how it's done:
RewriteRule ^([^/]+)/rss$ /rss.php?username=$1 [QSA,L]

rewriting single url help

I'm trying to rewrite the following url:
index.php?route=checkout/cart
to
/cart
using:
RewriteRule ^index.php?route=checkout/cart$ /basket [L]
However it doesn't seem to work. Anyone know what I'm doing wrong?
Thanks
RewriteRule does only test the URL path. You need RewriteCond to test the query:
RewriteCond %{QUERY_STRING} ^route=checkout/cart$
RewriteRule ^index\.php$ /basket [L,R=301]
The additional R=301 flag will cause an external redirect with the status code 301 (permanent redirect) instead of an internal redirect.
And if you want the other way round:
RewriteRule ^basket$ index.php?route=checkout/cart [L]
You need to send a redirect so that the new URL get reflected in browser address bar. So, add R to the [L].
RewriteRule ^index.php?route=checkout/cart$ /basket [R,L]
If you'd like that searchbots should ignore the "ugly" URL and/or remove it from the indexes and use the new instead, then send a 301 redirect.
RewriteRule ^index.php?route=checkout/cart$ /basket [R=301,L]

Problem in Multiwrite Rule

U have used rewrite url module but not able to redirect to the target page and I am getting error as The requested URL /old.html was not found on this server.
Here is my code. Please see to that and suggest to me:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^8080$
RewriteRule ^(.*)$ http://localhost/IN/$1 [L,R]
RewriteRule ^new.html$ /index.html$1 [L]
Your first rule will probably cause an infinite rule as the substitute URL doesn’t use the port 8080 neither. So try this:
RewriteCond %{SERVER_PORT} !^8080$
RewriteRule ^(.*)$ http://localhost:8080/IN/$1 [L,R]
You also need to request /new.html to see if your second rule works. Additionally, there is no first group in your pattern whose match can be referenced by $1. So:
RewriteRule ^new\.html$ /index.html [L]

Resources