GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech .htaccess question / url rewrite (?) (https://gfy.com/showthread.php?t=1352540)

Publisher Bucks 02-25-2022 03:15 AM

.htaccess question / url rewrite (?)
 
I know this should be possible but I'm having difficulty figuring out how.

I have a php variable at the top of my page like this:

Quote:

$collection = "blah blah something something";
What I'm trying to do is have it so that my .htaccess file will rewrite the URL of the page it is on to contain the verbiage inside that variable and that will become the url of the page like this:

domain.com/directory/blah-blah-something-something.php

Would anyone happen to know if this actually is doable, the page has a .php extension and secondly, would you happen to have the .htaccess code needed to make this happen?

Thanks for any help you can offer.

Oh and Happy Mardi Gras everyone :thumbsup

http://www.publisherbucks.com/mardigras.jpg

zijlstravideo 02-25-2022 03:59 AM

Sure, that's doable.

Your php file, it should look something like this:

$collection = "blah blah something something";
$actual_Link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$post_Link = preg_replace("![^a-z0-9]+!i", "-", strtolower($collection));
$post_Link = rtrim($post_Link, "-");
$rewrite_Link = "http://$_SERVER[HTTP_HOST]/directory/".$post_Link.".php";
if($rewrite_Link !== $actual_Link)
{
header("Location: $rewrite_Link,TRUE,301);
die();
}


And your htaccess something like this:

RewriteRule directory/(.*)\.php$ yourrealfile.php?id=$1 [L]

Not entirely sure about the htaccess part though. It looks a bit off. Anyway, it's untested, but I think it should point you in the right direction.


And make sure you get the value inside $collection from somewhere safe. Might want to check and verify if it's a match in your SQL database or something, before redirecting.

Publisher Bucks 02-25-2022 12:57 PM

Quote:

Originally Posted by zijlstravideo (Post 22969459)
Sure, that's doable.

Your php file, it should look something like this:

$collection = "blah blah something something";
$actual_Link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$post_Link = preg_replace("![^a-z0-9]+!i", "-", strtolower($collection));
$post_Link = rtrim($post_Link, "-");
$rewrite_Link = "http://$_SERVER[HTTP_HOST]/directory/".$post_Link.".php";
if($rewrite_Link !== $actual_Link)
{
header("Location: $rewrite_Link,TRUE,301);
die();
}


And your htaccess something like this:

RewriteRule directory/(.*)\.php$ yourrealfile.php?id=$1 [L]

Not entirely sure about the htaccess part though. It looks a bit off. Anyway, it's untested, but I think it should point you in the right direction.


And make sure you get the value inside $collection from somewhere safe. Might want to check and verify if it's a match in your SQL database or something, before redirecting.

Awesome, thanks, will have a play with this shortly :thumbsup

u-Bob 03-02-2022 11:07 PM

.htaccess :
Code:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ %{DOCUMENT_ROOT}/whereveryouwannakeepthis/404.php [L]

404.php:
Code:

<?php

$uri = $_SERVER['REQUEST_URI'];

$path = parse_url($uri, PHP_URL_PATH);

$filename = basename($path);

if($collection = substr($filename, 0, strpos($filename, ".php")) )
{
$collection = str_replace("-"," ",$collection);
print $collection;
}
else
{
http_response_code(404);
exit;
}

?>



All times are GMT -7. The time now is 12:41 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc