In my php page I have a hyperlink like:
Remove User";
The delete_user_page.php via GET takes the name of the user and executes the script. I want a URL rewrite mechanism inorder to hide the passed variable. So I wrote:
.htaaccess
RewriteEngine On #Turn on the re-writing engine
RewriteRule ^delete/?$ delete_user_page.php?name=$1 [NC,L] # Handle requests for "Delete users page"
When loading this onto the server and refreshing the results nothing has changed/showed so I realized I am doing something wrong.
Where does htcaccess have to be located relative to delete_user_page.php?
Looking at "delete_user_page.php?name=$1", is $1 correct or should it be different?
If there is something else wrong in my script please tell me.
Related
How would one go about creating a uri based on the information in the database. I know how I can post to a dynamic php page and have it search the database then use htaccess to rewrite that url. But how do I get php to generate a page based on a URI Link clicked lets say in a menu For example: The database will have a Unique title which will be the unique uri of the portion of the URL, Essentially the title is representative of the link uri in the "a href" link in a menu. So if somesite.com/ loads the main page, but if users clicks the link somesite.com/a-dynamic-page/ which would be a dynamically generated page. How do I get the server instead of throwing a 404 error because the page does not exist, have php look through the database and load the data from the database and then generate the page based on what was found in the database for "a-dynamic-page"<--unique uri in database? Let me know if you need any clarity on this question.
You probably want to first tell .htaccess to process all missing pages with some php script you've written, by putting this inside your .htaccess file:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my_processor.php [L]
</IfModule>
... which would effectively tell apache that all requests to pages that don't exist, should be redirected to a script called my_processor.php, directly on your website's document root.
Once inside the my_processor.php script, you can look at and parse $_SERVER['REQUEST_URI'], and use that to determine what your script should do next. ie:
[my_processor.php]
<?php
//
#$uri=$_SERVER['REQUEST_URI'];
switch($uri)
{
default: die("Error");
case "/some-path-1/":
SomeFunction1();
break;
case "/some-path-2/":
SomeFunction(2);
break;
}
?>
Please forgive how simple the above is, but hopefully you get the idea.
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'm trying to get a wordpress page to "run" another page based on the url. So if I have a main page like:
/extensions
That will run the regular extensions page. But if I have urls like:
/extensions/test
/extensions/test/again
/extensions/text/again/etc
They will all just run the extension (no "s") page:
/extension
The extension page will parse the url and do it's thing at that point. I tried setting up a redirect rule in the .htaccess file like so:
RewriteCond %{REQUEST_URI} ^/extensions/.*
RewriteRule . /extension [L]
But I can't seem to get it going. I'm assuming wordpress is always parsing via the index.php file, which is some how trumping my little rewrite possibly. Is there anyway to set this up on wordpress?
Found the answer here.
Note that this should go into the functions.php file and you will have to hit save in the permalinks settings EVERY time you make a change to the function to see the effects.
I just saw this somewhere, and I'm interested on it, and can't seemed to find it anywhere or I just used the wrong words to search for.
Well I saw this link,
http://splur.gy/r/QqVYf/r/2tgNklHgmVK
and when I clicked it, I got redirected to other page which called
https://www.facebook.com/xxx.xxx?sk=app_xxxx
Anyone knows how this thing was made? or just a little hint to start off?
A help would be nice. :)
These are done with RewriteRule, a simple Google search willgive you mroe details.
In short, the URL will be broken down sorta like this: (Line 1, URL part, Line 2, PHP relative.
http://splur.gy
http://splur.gy/index.php
r
$_GET['var_1']
QqVYf
$_GET['var_2']
r
$_GET['var_3']
2tgNklHgmVK
$_GET['var_4']
The RewriteMod will take the URL as setup in the above format, and pass the varialbes to a script. It is another way of posting variables in the URL.
As you see above: stackoverflow.com/posts/15182831, does not actually have a file named posts/15182831, it is simple used as a variable, passed to a script which queries that database, and spits out results based on what the script says.
You will need to have a server that will allow you to rewrite requests so you can redirect all requests to a single script. If you are running Apache, you would create an .htaccess file with something like this in it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^r$ /redirect.php [L,QSA]
RewriteRule ^r/(.*) /redirect.php?__q=/$1 [L,QSA]
</IfModule>
Then if you go to http://yourdomain.com/r/234243/adsfsd, the request will be sent to the script /redirect.php and '234243/adsfsd' will be passed as the GET paramiter 'q'.
Then you would create a file called redirect.php that would process the request and then redirect the user. It might look somthing like this:
<?php
$redirection = process_to_determine_location_from_query( $_GET['q'] );
header( 'Location: {$redirection}' );
?>
It's called a redirect. You can do it in PHP with this code:
<?php
header('http://example.com');
Another thing that might have happened is that the link you saw was not the actual link you follow when you click. It's as simple as doing this:
example.com
Anyone could do that.
http://www.google.com/
It has nothing to do with PHP.
i want to redirect
http://testsite.com/campus.php
to
http://testsite.com/campus.php
but the file campus.php doesn't exists. It fetches the page content from database and it must be displayed.
I haven't got any idea.
First of all, your two URLs are the same.
But if you want to call a page that doesn't actually exist but is pulled from the database, you typically redirect some part of the URL to point into a $_GET variable used to access the database. All requests actually go to index.php, and index.php handles the database and displays the correct data.
# Conisde this pseudocode
# Rewrite somepage to index.php?pagename=somepage
RewriteRule /somepage.php /index.php?pagename=somepage
# The actual .htaccess rewrite looks like:
RewriteEngine On
# Assuming pagename is upper/lower letters and numbers only...
RewriteRule /([A-Za-z0-9]+)\.php /index.php?pagename=$1
Now in your PHP, you use $_GET['pagename'] (campus in your case, I think) to call the text from the database and display it.
EDIT I added the \.php to the RewriteRule. Now /campus.php rewrites to /index.php?pagename=campus