mod_rewrite Internal rewrite with the new URL showing - apache

I am using Mod_Rewrite to rewrite (internal) some old pages to new pages on my site.
This works:
RewriteRule ^thispage\.html$ thatpage.html
The problem is that the page changes to the new page (this is good!), but does not change the (URL) name from "thispage" to "thatpage" so the user gets hinted to the new address. Apache (2.x) states to place a [R] after the above script, i.e.,
RewriteRule ^thispage\.html$ thatpage.html [R]
This supposedly lets the user know it is changed and sends them to the new page.
When I add the [R], I get a 500 error. The server is an Apache/1.3.33.
I am thinking that the only way to force the server to show the new url is to use a redirect instead on rewrite. Any ideas?
Any help is sincerely appreciated!

Have you tried this?
RewriteRule ^thispage.html$ thatpage.html [R=301,L]
Alternatively, a Redirect would be easier on the server than a Rewrite...
Redirect 301 thispage.html http://yourDomain.com/thatpage.html

For not display new url, you must delete [R], because
[R] is for display new url

Related

Apache mod_rewrite

I'm using Liferay 6.2 EE that runs on tomcat but it's fronted by an Apache server. I want to redirect users so that whenever they hit the old liferay URL, it redirects them to the new liferay URL. I changed the URL in liferay, so it is now the new URL. However, whenever I try to go to the old URL, I get a page request error. It never redirects me to the new URL. In /san/apache/conf/ I put my redirect code inside of httpd.conf. This my code:
RewriteEngine On
RewriteRule ^group/old/(.*) /group/new/$1 [L]
After I applied these changes, I restarted the Apache server and it still doesn't work. I've tried a bunch of other combinations as well. Does anyone know what I'm doing wrong? Is there some place else I have to make this change?
Ah, since your rewrite rule is lying in the server config file (instead of htaccess file), the mod-rewrite receives URLs with the leading slashes (/). So, the rule should be:
RewriteEngine On
RewriteRule ^/group/old/(.*) /group/new/$1 [L]

Rewrite URL .htaccess - Apache server

On my website, I would rename the URL on address bar, from
domain.com/economy/article.php?id=00
to
domain.com/economy/id-name-article.html
I wrote this .htaccess file:
RewriteEngine On
RewriteRule ^([0-9]+)-([^\.]*)\.html$ http://domain.com/economy/article.php?id=$1 [L]
I have an anchor with this href: href="economy/id-name-article.html" and when I click on it, the server is redirected on article.php, it runs the script in the correct way and I can view the article, but on the address bar is still written domain.com/economy/article.php?id=00 instead domain.com/economy/id-name-article.html. Why?
This happens only on my online server, while locally it's all right.
The mod_rewrite module is issuing a redirect to your browser rather than transparently rewriting the url, causing you to see the new url in your browser.
Try removing the http://domain.com portion from your RewriteRule to see if it avoids the redirect to your browser by changing the rule to:
RewriteRule ^([0-9]+)-([^\.]*)\.html$ /economy/article.php?id=$1 [L]
If that fails, you could also use the proxy flag [P] to force apache to transparently fetch the page and return it to your users without the redirect. I don't recommend this approach since it can have security implications but it should work if the above doesn't.
EDIT: To clarify, rewriting the url with a fully-qualified domain rather than a relative uri tells apache that the redirect is on a different server, and therefore it doesn't know that the new url is accessible on the same host without redirecting the client.

mod_rewrite to redirect url not working

Cannot seem to get a mod_rewrite to work. We have a domain name that has already been printed here, there and everywhere when the website was Flash. It has a # in its trail /#login.php and we want so that when people put this in it redirects them to /login.php. I have already tried this rule but can't get it to work:
RewriteEngine On
RewriteRule ^/#login.php$ /login.php
I have also checked that the rewrite engine is working by using a redirect to google. Just need the out of date #login.php to go to the new login.php
thanks
The # in the URL (or "fragment") is not sent to the server, it's purely for the client side to point to some part of the page. If you see http://hostname.com/#login.php in your address bar, the only thing the server gets is a request for /. You may need to employ some javascript on the page to look at the browser's address bar to find a fragment and maybe send that to the server as a query string.
Try :
RewriteEngine On
RewriteBase /
RewriteRule ^#login\.php$ /login.php [QSA,L]
Mod_rewrite is enabled ? available ?

Redirect to new URL`s

i want Redirect the old url`s to new address.
Redirect all
http://www.mysite.com/viewdownload/**/**
url`s to
http://www.mysite.com/download/viewdownload/**/**
example:
http://www.mysite.com/viewdownload/21/323
Should be Redirect to
http://www.mysite.com/download/viewdownload/21/323
or
http://www.mysite.com/viewdownload/13/961
Should be Redirect to
http://www.mysite.com/download/viewdownload/13/961
RewriteRule ^(viewdownload)/(\d+)/(\d+)/?$ download/$1/$2/$3 [L,R=302,QSA]
If this does what you'd like it to after some testing, change R=302 to R=301.
If you are using Apache this is something for mod_rewrite / url rewriting & not Joomla.
You got the wrong keywords. Search for mod_rewrite or come back if you need more help.

apache .htaccess - cut a string from url and redirect

For some reason google indexed several pages of my website as:
http://myapp.com/index.php/this-can-be-enything/1234
Now, I want to redirect with apache .htaccess those pages to correct urls:
http://myapp.com/this-can-be-enything/1234
I've googled and tried many options but with no success.
Any tip will be helpful.
I've added to my .htaccess file following lines:
RewriteCond %{THE_REQUEST} ^.*index.php.*
RewriteRule ^(.*)index.php(.*)$ $1$2 [NC,R=301,L]
I don't know if this is best solution but works ok for me.
Two Parts of problem
To make Google aware that indexed page is moved to some other destination you need to handle that # apache level and issue 301 ( moved permanently )
Handler to handle the cached requested URL to new URL using the #1 handler itself.