hello i have an anchor on my site. by calling my site the url will be:
http://site.com/page.php
by clicking a button the url will display an url that i would like to hide:
http://site.com/page.php#1
now i have found out that i can change this by using mod_rewrite tool. i tried this rule without success:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^.*\.html$ %1.php [L]
for calling the page as html or php and to hide the #1 behind the .php
RewriteRule ^(.*)$ ./php#1=php$1
i really would appreciate if there is someone who could give me advise on how to solve this. thanks a lot.
You cannot achieve this via mod_rewrite.
URL after # are not passed through server.
If you still want to achieve this, you may want to look into doing it via JavaScript:
Check this out
JavaScript:
function scrollHere() {
// Scroll to the anchor
//(you may need to look for some script to achieve this)
return false; // to prevent URL overwriting
}
One such script is this jQuery.scrollTo.
The hashtag is never sent to the server, thus you simply cannot create a rule, that based on it.
You can do something like this to remove # tag.
Your text.
So when you write "javascript:void(0);" in href attribute of a tag and thats it.
HTML
<a href='page'>Home Page</a>
<a href='page/1'>Page 1</a>
<a href='page/2'>Page 2</a>
<a href='page/3'>Page 3</a>
Rewriting as
RewriteRule ^$ page.php [L]
RewriteRule ^([a-z]+)/?([0-9]*)/?$ page.php?index=$2 [L]
And check for index in php
<?php
if (isset($_GET['index']))
{
$pageNo =$_GET['index'];
}
//based on page NO display contents
?>
Related
There's some way to hide all redirect from URL,
or maybe just show my domain on every click
I've tried to use this in .htaccess but the sample.com/#some is not gone just (.php) is hide.
RewriteEngine On
#remov php exten
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)$ /%{REQUEST_URI}.php [NC,L]
#redirect root to sub
RewriteRule ^((?!).*) /%{REQUEST_URI} [L,NC]
RewriteRule ^((?!).*)/#{REQUEST_URI} [L,NC]
any good idea?
The hash in the URL is client-side only. So it is not sent to the server, so you would never change it via .htaccess file.
However, you could use some javascript codes to remove it like this:
$('a').click(function(){
removeHash();
});
function removeHash () {
window.location.href = window.location.href.split('#')[0]
}
Do not forget to modify $('a') with your ids if you need. Currently the code above is removing all #somes when any link is clicked.
Updated:
Or you can completely prevent from page refresh incase you want to use onclick attribute of a element. In that case, use below function instead.
function removeHash () {
window.location.hash='';
}
This is a link on index.php page
<?= $mbbelow['brand_name']; ?><?= $mbbelow['title']; ?>
from this link I come on page specification.php
then this url come http://www.themobilesapp.com/specification.php?url=Sony-Xperia-Z5-specifications-5246.php
in the base of url I find all data of page.
This url is not proper according to me.
Here I want to remove specification.php?url= from this above url.
Please tell me in proper and full explain way that how to remove and make new url like this
http://www.themobilesapp.com/Sony-Xperia-Z5-specifications-5246.php
I only need .htaccess or I also need to work using php code to remove this.
I will provide you all details you need here for to remove this.
Please try this in .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ specification.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ specification.php?url=$1
This is my input URL
http://site_name/project/edit/sgdsg/getFile/?file=271bbec45d7855a332e6dfda85ca94b9.txt
I want it to be sent like
http://site_name/project/edit/sgdsg/getFile/271bbec45d7855a332e6dfda85ca94b9.txt
How can we do this? I want this only for the URL starting with http://site_name/project/edit/sgdsg/getFile/
So it don't affect any other URL.
This is what I have tried ...
RewriteRule ^project/edit/([A-Za-z0-9._-]+)/([A-Za-z0-9._-]+)/([A-Za-z0-9._-]+)/?$ modules-nct/edit_project-nct/index.php?slug=$1&action=method&method=$2&file=$3 [L]
RewriteRule ^project/edit/([A-Za-z0-9._-]+)/([A-Za-z0-9._-]+)/?$ modules-nct/edit_project-nct/index.php?slug=$1&action=method&method=$2 [L]
RewriteRule ^project/edit/([A-Za-z0-9._-]+)/?$ modules-nct/edit_project-nct/index.php?slug=$1 [L]
Please don't give it negative ratings just because my editing is improper.I am here to learn something new.
Thanks.
In your <a> tag:
<a href="your_url/your_other_parameters(means :project/edit/sgdsg/getFile/ )/directly enter your file name that you want to pass"> i.e your <a> tag must be
In htaccess:
RewriteRule ^project/edit/([A-Za-z0-9._-]+)/([A-Za-z0-9._-]+)/([A-Za-z0-9._-]+)$ modules-nct/edit_project-nct/index.php?slug=$1&action=method&method=$2&file=$3
In the above line, the href URL will be redirected to an original URL.
I'm trying to convert my app links, so that a link like this:
http://localhost/index.php?id=13&category=Uncategorized&title=just-a-link
gets converted to this:
http://localhost/13/Uncategorized/just-a-test
so far I was able to do it using:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
but that completely breaks links to css and other files as it redirects every request with query to index.php
so I changed it slightly so that it only runs when the first query is a number:
RewriteEngine On
RewriteRule ^([0-9]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
this one doesn't break css and js files, however when you go to the link for example http://localhost/13/cat/test then try to go to another link like http://localhost/19/Uncategorized/something by clicking on it inside the previous page it will instead redirect you to something like http://localhost/13/Uncategorized/19/Uncategorized/just-a-test
How do I achieve what I described without any of these weird side effects??
Use :
RewriteEngine On
RewriteRule ^([0-9]+)/([^/.]+)/([^/.]+)/?$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
And add this code to your html <header>:
<base href="/">
OR
<base href="http://www.domain.com/">
To fix relative css and js links
I have the following PHP code:
<?php
if(isset($_GET['article']))
{
echo "<b>success</b>";
}
?>
And this html:
<a href="http://localhost/PHPTest/index.php?article_27" >Click me</a>
I am trying to come up with my own url.
By doing so, I try to use mod_rewrite(). This is what is in my .htaccess:
RewriteEngine On
RewriteBase /PHPTest/
RewriteRule ^article_([0-9]+)$ index.php?article=$1
As you can see, I try to get the article get variable..
This however doesnt work.. The htaccess does not comprehend artcile_27, for example, as article=27..
Why is that?
What should happen is that the success word should be printed whenever I press the link. The problem is that it does not.
The rule you have written would match the link http://localhost/PHPTest/article_27, if you really want to have the URL http://localhost/PHPTest/index.php?article_27 matched (which is an, at least in my oppionion, unusual URL), the correct Rewrite Rule would be the following:
RewriteRule ^index\.php\?article_([0-9]+)$ index.php?article=$1
You have to look at the whole part after the last slash.
Your rule should be:
RewriteRule ^index.php?article_([0-9]+)$ index.php?article=$1
However, I'd question the use of mod_rewrite in this way.
First of all, if your url is always just index.php?article_27 then you can get directly at "article_27" using $_SERVER['QUERY_STRING'], without mod_rewrite at all.
If you're going to use mod_rewrite, why not have your URL be /PHPTest/article/27?
RewriteRule ^article/([0-9]+) index.php?article=$1
The above will also allow /PHPTest/article/27/title_of_article_here, which gives you two nice things: the ID is still there so it's easy to retrieve server-side, and the name is in the URL so it's nice to read as a human and helps search engines. If you look in your URL bar now, you'll notice stackoverflow itself uses this method.
Open this: http://localhost/PHPTest/article_27
If it works, it means that your rewriting works. In that case, all you have to do is change the HTML:
<a href="http://localhost/PHPTest/index.php?article_27" >Click me</a>
Should be:
<a href="http://localhost/PHPTest/article_27" >Click me</a>
Or rather, just:
<a href="/PHPTest/article_27" >Click me</a>
Which makes your code more portable to another hostname, port, protocol ...