Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 453 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.htaccess appending URL Slugs with the anchor tags

#1
I am creating a blog in Core PHP to get a better understand of the core functionalities of CMS. However, I am facing a challenge in the menu when I am displaying a single post.

I am using the below `.htaccess` code

# code to make pretty URLS | we're using this code to achieve /category/slug
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/([\w-]+)/([\w-]+)$ app/post.php?&category=$2&slug=$3 [L,QSA]
RewriteRule ^(.+)/([\w-]+)$ app/post.php?category=$2 [L]

The above code will convert `www.example.com/post.php?category=some&slug=title-ti` to `www.example.com/some/title-ti`

Now what's happening is when i am on the index page i am dynamically generating menu. So the menu are as per the slugs.

`Technology
- usage-tips
- overview
`

the above menu URLs will be like `www.example.com/technology`, `www.example.com/usage-tips', 'www.example.com/overview'

but when I open single post page

the URL that I have is `www.example.com/technology/demo-post`

and the Menu URL's that I get is

the above menu URLs will be like `www.example.com/technology/technology`, `www.example.com/technology/usage-tips', 'www.example.com/technology/overview' and more going into it is like an endless loop.

If I inspect the element it's `www.example.com/usage-tips` and so on, but when I am clicking or hovering the links then I am redirected to `www.example.com/technology/usage-tips` links

What's going on is there an error with my php code or the `.htaccess` code

following is my dynamic header code

$query = ' SELECT id, name, slug FROM categories WHERE status = 1 AND parent_id = "'.$parent_id.'" ORDER BY priority ASC ';
$connection = $this->establish_connection();
$data = $connection->query($query);
$connection->close();
if($data->num_rows > 0)
{
$putclass = $menu = "";
while($row = $data->fetch_assoc())
{
if($arrow_status)
{ $putclass = ""; }
else
{ $putclass = "drop"; }

$menu .= '<li class='.$putclass.'><a href="'.$row["slug"].'">'.$row['name'].'</a>';
$menu .= '<ul class="dropdown">'.$this->menu($row["id"], true).'</ul>';
$menu .= '</li>';
}

return $menu;
}

This is my post.php code

<?php
// print_r($_GET);
?>
<?php
if(isset($_GET['category']) && isset($_GET['slug']))
{
?>
//some content if both are set
<?php
}

elseif(isset($_GET['category']) && !isset($_GET['slug']))
{
?>
//some content if only category is set
<?php
}
?>
Reply

#2
You want to be using `absolute-path reference` this way the browser will start from the root of your site, rather than the current directory. To use that start the `href` with a leading `/`.

$menu .= '<li class='.$putclass.'><a href="/'.$row["slug"].'">'.$row['name'].'</a>';
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through