i have an url like
http://example.com/folder1/folder2/admin_login.php
the above is active page. but i want to show the below url instead of above but functioning the same page.
http://example.com/folder1/folder2/login
So the question is display url-2 in browser but exeuctes url-1
i have tried this code in htaccess file
RewriteEngine on
RewriteRule ^folder1/folder2/admin_login.php$ http://example.com/folder1/folder2/login [NC,L]
When i put url-1 in browser address bar. it will convert into the url-2 but shows Page Not Found
You have it turned around. You want the second url to be in the address bar. That means you have to link to that url. When a request with that url comes to the server, the server has to internally translate that url to a working url. Besides that, you should not have the full url as a rewrite target, because this causes the rule to function as a redirect instead of an internal rewrite.
The following rule should do the trick:
RewriteRule ^folder1/folder2/login/?$ /folder1/folder2/admin_login.php [L]
Related
I have a Two URLs
NEW URL :
http://host.ip.address/nl/business/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart
OLD URL :
http://host.ip.address/nl/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart
when in request NEW URL from browser it should retrieve content from OLD URL and the URL should not change in browser.
I have tried the below rule in .htaccess it is rewriting and redirecting to the OLD URL which should not do in my case
RewriteEngine on
RewriteRule (^|.*?/)nl/business/(.*)$ /$1nl/$2 [L,R=301]
It is not possible to do a redirect and keep the original URL in the address bar." This is because a redirect, by definition, involves telling the browser to ask for the requested resource at a different URL. So the browser updates its address bar and uses the new URL.
The simplest way would be use a rewrite, not a redirect. An internal rewrite simply serves content from a local file-path that is different from the requested local URL-path.
You can use something easy like this.
RewriteEngine On
RewriteRule nl/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart nl/business/producten-en-diensten/gsm-en-smartphones/samsung-galaxy-j1-2016-zwart
You may need to also add
Options +FollowSymLinks
i tryed to search everywhere for this problem but i didnt found nothing.
I want to make make a url seo friendly so i used this code:
RewriteEngine on
RewriteRule ^Homepage index.php [NC,L]
Then i want to redirect to it so i tryed to write this code:
RewriteRule ^index.php$ http://localhost/siti/socialmark/Homepage [R=301,L]
The error it's a loop of redirections, can someone help me?
SORRY FOR MY BAD ENGLISH!
The rewrite rules don't just make the URL string look different, it actually directs the user to the file at the end of the path even if you don't see it in the address bar. If Homepage is a directory containing index.php, even if that php file name doesn't appear in the URL, then it's causing a loop because it's directing you to a directory with an index.php.
The rule is executed every time that page loads. So, you're redirecting to a page which runs the redirect script, so it runs the rule to redirect again, and that causes the loop. What you want to do is create a condition that says "Don't run this code if the requested page is http://localhost/siti/socialmark/Homepage"
Something like this (you may have to adjust it)
RewriteBase /
RewriteCond %{REQUEST_URI} !=/siti/socialmark/Homepage
RewriteRule ^Homepage index.php [NC,L]
For more details, see the caveats and example here:
http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_l
I have a website where my links look like this
http://www.domain.com/index.php?lang=English&inc=canyoning
I managed to write rewriteRule like this:
RewriteRule (German|English)\/(.*) http://www.domain.com/index.php?lang=$1&inc=$2 [NC,R]
Now my links look like this: <a href="http://www.domain.com/English/canyoning">...
This works, but I can see non user friendly URL in browser address bar. How can I tell browser to use link like /English/canyoning in URL and not index.php?lang=English&inc=canyoning?
And second: I would like to use forms on page.
There is no difference, whether I use form method =GET or POST, No variables come to destination site.
I guess there is my rewriteRule wrong. How to fix those issues?
Thank you for help!
This is because you are doing a redirect not a rewrite.. (The R flag indicates a Redirect)
So remove the R flag should fix your issue.
You may also need to remove the hardcoded domain. As you are doing a rewrite you cant rewrite to a different domain.
ie. Change
RewriteRule (German|English)\/(.*) http://www.domain.com/index.php?lang=$1&inc=$2 [NC,R]
To
RewriteRule (German|English)\/(.*) /index.php?lang=$1&inc=$2 [NC]
I'm just trying to display css content at http://mydomain.com/dynamic_css/presets/
when user's browser loads http://mydomain.com/css/dynamic.css using the following
RewriteEngine on
RewriteRule ^dynamic\.css$ http://mydomain.com/dynamic_css/presets/ [QSA,L]
But instead browser gets http 301 redirected to http://mydomain.com/dynamic_css/presets/
Any idea why ?
Basically, the script at http://mydomain.com/dynamic_css/presets/ shows up a CSS generated code to allow more styles control from admin settings.
You can't specify the full domain in your request. mod_rewrite assumes this is an external URL which can only be handled via redirect. Try the below instead.
RewriteRule ^dynamic\.css$ /dynamic_css/presets/ [QSA,L]
I have written a rule for redirecting in .htaccess file
its redirecting for some pages , if we give that link manually..
but what i want is ,it should redirect automatically....
My requirement is :
Instead of this link,
links.php?page=1&ipp=All&exchange=adddata
It should be redirected automatically
http://example.com/folder1/links/1/All/exchange.html
MY rule in .htaccess is
RewriteEngine On
RewriteRule ^([0-9]+)/All/exchange.html$ links.php?page=1&ipp=All&exchange=adddata
It's not completely clear by your example, but it could be this:
RewriteEngine On
RewriteRule ^links.php?page=([0-9]+)&ipp=All&exchange=adddata$ folder$1/links/$1/All/exchange.html
In the comment above you mistakenly swaped the original url and the url it should be redirected to plus you didn't set any dynamic parameters in your new url - which I suppose you need. But as I said, to be sure about it we'd need more examples.
Hope this helps!