Change URL in address bar but keep on same page - mod-rewrite

Is it possible to rewrite a url so that the page stays the same and the url itself is chanaged ?
E.G.:
I have a page at www.example.com/sales
I want this url to appear in the address bar as www.example.com/sales_and_repairs
I am NOT trying to redirect a page at www.example.com/sales to ANOTHER page at www.example.com/sales_and_repairs ....There is only ONE page - it is just the URL I am trying to change so that if a person types in www.example.com/sales, they will go to that page but the URL in the Address bar will change to show as www.example.com/sales_and_repairs
Is this possible with rewrite rules ? Anytjhing I have looked up appears to suggest that you have to be redirecting to a second page - but that is not what I want to do - I just want to change the actual URL.
Any advice please ??

If you want to redirect www.example.com/sales_and_repairs to www.example.com/sales permanently you can do it with an .htaccess file.
First of all, you'll have to enable mod_rewrite in apache.
Then add the following to your .htaccess file :
Options +FollowSymlinks
RewriteEngine on
Rewriterule ^http://www\.example\.com/sales_and_repairs$ http://www\.example\.com/sales [R=301,NC,L]
This method allow you to have only one file behind the two urls.
However if you want to modify the url after a user's action, you can do it with the answer given by Sparda above.

Seems you can achieve this with javascript :
location.hash = 'newurl';
But this will add an anchor to the url.
Some earlier features of html5 can do this but are not really supported yet :
history.pushState(data, 'title', 'newurl');

Related

Rewrite base url to show content of cms page

Trying to rewrite a base url e.g http://beta.mydomain.com to http://beta.mydomain.com/cms/index.cfm/new-home but want browser to show base url not the cms url.
Im trying this in isapi httpd config file:
RewriteRule ^$ /cms/index.cfm/new-home [NC,L]
but it simply redirects to http://beta.mydomain.com/cms/index.cfm/new-home
which is correct except that the browser must show http://beta.mydomain.com/ not the cms part.
We are using IIS 6 with isapi module installed. Thats the only thing I know about the server (but I have access to server). Is that possible? If not then what other options do I have?
I have an idea: Load http://beta.mydomain.com/cms/index.cfm/new-home in an iFrame.
For example if someone browser to base URL i.e. http://beta.mydomain.com/ then load http://beta.mydomain.com/cms/index.cfm/new-home page in iframe.
It should be like a condition at top of your index page.
if (only baseURL) {
iFrame: Load http://beta.mydomain.com/cms/index.cfm/new-home
}
Hope this help :)

Google Ajax crawling is failing

I have a php ajax website that serves pages to my users like
http://www.example.com/ => this has all the individual page contents like listing
http://www.example.com/#!page1-uid => has page1 contents, uid is the unique mongoDB identifier for that page
http://www.example.com/#!page2-uid => has page2 contents, uid is the unique mongoDB identifier for that page
I want google to crawl my website to index all of about 200+ pages but none of them are getting indexed
I pretty much followed and understood the google ajax crawling methods but not sure where/what i am still missing.
Here is the setup:
.htaccess
RewriteCond %{HTTP_USER_AGENT} (googlebot|yahoo|bingbot|baiduspider) [NC]
RewriteCond %{QUERY_STRING} _escaped_fragment_=(.*)$
RewriteRule ^(.*)$ botIndex.php?QSA=%1 [QSA,L]
botIndex.php
$var1 = $_REQUEST['QSA'];
checks if QSA is set, if so, serves the individual page1/page2
else gives out the default home page that has the listing of all the page links
When I tested using GWT ( "fetch as google" ), here is the pattern i observe
a) www.example.com/ => it gets redirected to botIndex.php and returns me all the links (default view) just as expected
b) www.example.com/#!page1-uid => redirects to the botIndex.php and returns me all the links but ideally it should return the actual page content instead of the home page contents (not sure GWT has the ability to ask for _escaped_fragment_ to mimic googlebot)
c) www.example.com/?_escaped_fragement_ => GWT returns "Not found" error
By adding few echo in the botIndex.php, What i suspect is none of the above requests shows that the "_escaped_fragment_" is caught
hence my script botIndex.php does not get the value of the QUERY_STRING (QSA) to serve the page1/page2 individual pages instead always
defaults to home page showing all the page listing.
I tested the URL's directly for botIndex.php like
a) http://www.example.com/botIndex.php?_escaped_fragment_=QSA= (returns all the links )
b) http://www.example.com/botIndex.php?_escaped_fragment_=QSA=page1-uid (returns the actual page details)
What am i still missing ?
I strongly believe the .htaccess has the issue which is not possibly passing the QSA to my script.
Please suggest.
UPDATE: I am still stuck. Anyone can help me with some pointers ?
Evidently, you have problem with preserving GET parameters during rewriting. Try to debug you .htaccess directives.
Another option is to create one entry point for your php app, just like all modern frameworks do. And implement all the logic (serving html content for bots) in your php app.

iirf rewrite url

i'm trying to use iirf for what looks like asimple rewrite but it's not working.
what i need:
rewrite http://www.mydomain.com/ru to : http://www.mydomain.com?page=russian
the objective being that a get param would be sent but the user would see the first url on their browser's url bar.
i'm using the following code:
RewriteEngine ON
StatusUrl /iirfStatus
RewriteRule http://www.mydomain.com/ru http://www.mydomain.com?page=russian
does this go (the iirf file) on the site's root or in a 'ru' subfolder (tried both)?
what am i doing wrong or missing?
thanx and have a nice day :-)
The following should work:
RewriteRule ^/ru$ /?page=russian [I,L]
You should put this in the iirf.ini file in the web sites root folder.
Check http://www.mydomain.com/iirfStatus to see whether iirf was able to read your configuration file.
Also, you may use RewriteLogLevel with a value of 2 or 3 and RewriteLog to see whether the incoming url was rewritten, and how (or why not).

mod_rewrite and not displayed picture

There is index.php and logo.gif files in my server.
I need to change the way of display an adress from example.com/?nr=33&id=foo to example.com/33/foo or example.com/33/foo/. I have type in .htaccess this code
RewriteRule ^([^-]+)/([^-]+)$ /?nr=$1&id=$2 [L].
It almost works, but when I use example.com/33/foo logo.gif (with is used in index.php) dissapears in a browser. Can you show me mistake in it?
When you enter a URL like example.com/33/foo in your browser, your browser will assume it is in a directory of that name, and request the (relative) URL logo.gif as
www.example.com/33/foo/logo.gif
Reference the image as
/logo.gif
and it should work.

joomla - SEO settings and mod_rewrite

I'm using Joomla 1.5.14 and I configured SEO as in the following image
Now I need to map a few old URL to the new site
let's say that I need to map htp://mysite/old.html to the new Joomla page
http://mysite/index.php?option=com_content&view=article&id=32&Itemid=70
I added in my .htaccess file the following
RewriteRule ^old\.html$ index.php?option=com_content&view=article&id=32&Itemid=70 #works!!
this works fine, but if I use the SEF URL in .htaccess (let's say the above page can be reached with htp://mysite/contacts.html), I obtain a 404 error
RewriteRule ^old\.html$ contacts.html #this does not work
Now the question:
Is it possible use SEF URLs in RewriteRule? where am I wrong?
thank you in advance
stefano
I think the problem is because Apache rewrites old.html to a page that doesn't actually exist, but rewritten in a different rule.
If you truly want to "rewrite" - in other words, have the page stay as old.html in the browser - then you don't need to do anything.
However to avoid duplicate content it's probably better to do a 301 redirect:
Redirect 301 old.html http://yoursite.com/contact.html
(You may need a forward slash at the front of old.html)

Resources