Jump to content

experts please take a look seo url issue


Go to solution Solved by requinix,

Recommended Posts

guys i got this code

RewriteBase /site/

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ post.php?id=$1 [QSA,L]


RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ cat.php?cat=$1 [QSA,L]

the post.php works ok but then the cat.php redirects back to index.php and if i remove from the htaccess the post.php part

 

 

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ post.php?id=$1 [QSA,L]

 

then the cat.php code works ok on the browser

 

what is wrong in these codes please help out someone to make my urls work.

 

thanks

Edited by lovephp

doing so also does not work instead i get page not found error

 
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ cat.php?cat=$1 [QSA]

RewriteRule ^(.*)$ post.php?id=$1 [L]
 

but if i remove the line RewriteRule ^(.*)$ post.php?id=$1 [L] then the category works and if i remove the RewriteRule ^(.*)$ cat.php?cat=$1 [QSA] then the post works but both together i get page not found error

Edited by lovephp

Do you know what a pattern is? Do you know what those symbols mean or are you just copy-pasting?

 

I'm no expert in this area, but having the same pattern twice has to confuse the process. You are saying "if you have an A in your name, turn left" and then in the next line saying "if you have an A in your name, turn right".

As has been stated repeatedly, you cannot use both of those Rules because they both apply to the case when a URL does not exist.

 

Let's just forget all this and start from the beginning.

 

What URLs are you trying to rewrite to post.php and to cat.php?

As has been stated repeatedly, you cannot use both of those Rules because they both apply to the case when a URL does not exist.

 

Let's just forget all this and start from the beginning.

 

What URLs are you trying to rewrite to post.php and to cat.php?

Yes page i got two pages which fetching the url from database one is for category that is cat.php and another one is post.php the query seems to be working ok but only issue is with htaccess now only one works at a time if add another then either i get page not found for entire dir or the link just redirects back to index.php.

 

I got no idea how i can make this work anymore :-(

Do you know what a pattern is? Do you know what those symbols mean or are you just copy-pasting?

 

I'm no expert in this area, but having the same pattern twice has to confuse the process. You are saying "if you have an A in your name, turn left" and then in the next line saying "if you have an A in your name, turn right".

Honestly speaking mate htaccess is not my field so im having a really tough time.

Okay, maybe I wasn't clear.

 

What are some actual URLs you are trying to rewrite? Not a description. Actual examples.

Ok site url looks like

 

http://site.com/categoryname

 

http://site.com/post-title

 

Im using localhost but it should looks like this in real too.

I recommend not doing that: there's no separation between categories and posts. At the very least you should put categories under a "subdirectory" like /category/categoryname.

http://site.com/category/categoryname
http://site.com/post-title
If the majority of your site revolves around posts then you can leave it at the top (/post-title) but if you have many other pages that are not posts then you should give them a directory prefix too (/post/post-title).

Turn your brain on, dude.

 

You cannot use the same URL pattern for categories and posts. It's not possible. No SEO expert can do it. Not even Chuck Norris can do it. It's nonsensical.

 

Let's say I had this URL:

https://mysite.com/paris

Tell me: Is that a category or a post? You don't know, right? Well, then how on earth is Apache supposed to know?

 

Apache has to be able to distinguish between categories and posts. You need two different URL patterns. For example, posts could be subresources of categories:

https://yoursite.com/some-category/some-post

Or you could have two entirely separate paths:

https://yoursite.com/categories/some-category
https://yoursite.com/posts/some-post

Whatever you do, the URLs of categories and paths must be distinguishable.

  • Like 1

I recommend not doing that: there's no separation between categories and posts. At the very least you should put categories under a "subdirectory" like /category/categoryname.

http://site.com/category/categoryname
http://site.com/post-title
If the majority of your site revolves around posts then you can leave it at the top (/post-title) but if you have many other pages that are not posts then you should give them a directory prefix too (/post/post-title).

 

yes exactly how do make the category like category/categoryname? my site mostly depends on post so i believe can let the site.com/post-title as it is but only category i need to fix now.

Turn your brain on, dude.

 

You cannot use the same URL pattern for categories and posts. It's not possible. No SEO expert can do it. Not even Chuck Norris can do it. It's nonsensical.

 

Let's say I had this URL:

https://mysite.com/paris

Tell me: Is that a category or a post? You don't know, right? Well, then how on earth is Apache supposed to know?

 

Apache has to be able to distinguish between categories and posts. You need two different URL patterns. For example, posts could be subresources of categories:

https://yoursite.com/some-category/some-post

Or you could have two entirely separate paths:

https://yoursite.com/categories/some-category
https://yoursite.com/posts/some-post

Whatever you do, the URLs of categories and paths must be distinguishable.

totally agree and yes i realize now the issue but how do i change the htaccess to make it work that way? do i even have to change coding in php?

Here's what you had to start with.

RewriteBase /site/

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ post.php?id=$1 [QSA,L]


RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ cat.php?cat=$1 [QSA,L]
1. Since categories are going to start with "/category", you have to edit the stuff that matches categories to suit. Try it.

 

2. Rules are executed in order. It's okay if two rewriting rules can technically match the same URL, but you have to make sure that the first one to match is always the one that is supposed to match.

"/category/category-name" will match both the post rules (not a directory, not a file, and matches the RewriteRule) and the category rules (not a directory, not a file, and matches the RewriteRule you've just fixed), so you need to move them around so that the category one matches first.

 

If it still doesn't work after you address the two things above, post what you have.

i tried this

 

 

RewriteBase /site/
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ post.php?id=$1 [QSA,L]

RewriteRule ^category/(\d+)*$ cat.php?cat=$1

 

and here is the cat.php codes

 

$stmt = $db->prepare('SELECT catID, catName, catUrl FROM blog_categories WHERE catUrl = :catUrl');
$stmt->execute(array(':catUrl' => $_GET['cat']));
$row = $stmt->fetch();

//if post does not exists redirect user.
if($row['catUrl'] == ''){
    header('Location: ./');
    exit;
}

 

i tried to access it as http://localhost/site/category/name and i get error "The page isn’t redirecting properly".

1.

RewriteRule ^category/(\d+)*$ cat.php?cat=$1
That is incorrect. Drop the unnecessary (and problematic) * from it.

 

But you know that only matches numeric categories, right? Because \d is a digit which means \d+ is a number. "name" won't match.

 

2. Redirecting to ./ will send the user to /category. Are you sure that's what you want?

1.

RewriteRule ^category/(\d+)*$ cat.php?cat=$1
That is incorrect. Drop the unnecessary (and problematic) * from it.

 

But you know that only matches numeric categories, right? Because \d is a digit which means \d+ is a number. "name" won't match.

 

2. Redirecting to ./ will send the user to /category. Are you sure that's what you want?

 

no thats not what i want all i want is to be able to display site.com/category and posts related to that category name but guess its just too tough to achieve it. 3 days i been trying but but knowledge in htaccess is less so tried asking friends even they could not solve this :)

  • Solution

It's not too tough. As I see it, the main problem is that you know just enough to venture out and try doing everything, but you don't know what you actually need to know.

 

1. If you want actual category names then use .* instead of \d+

2. If you want /category to show, presumably, all categories, then fix your cat.php so that if "cat" is empty then it shows all categories instead of redirecting.

1.

RewriteRule ^category/(\d+)*$ cat.php?cat=$1
That is incorrect. Drop the unnecessary (and problematic) * from it.

 

But you know that only matches numeric categories, right? Because \d is a digit which means \d+ is a number. "name" won't match.

 

2. Redirecting to ./ will send the user to /category. Are you sure that's what you want?

 

did like u said mate and now problem solved

 

 

RewriteRule ^post/(.*)\?*$ post.php?$1 [L,QSA]

RewriteRule ^category/(.*)\?*$ categories.php?$1 [L,QSA]

RewriteRule ^tag/(.*)\?*$ tag.php?$1 [L,QSA]
 

 

thanks aton

Turn your brain on, dude.

 

You cannot use the same URL pattern for categories and posts. It's not possible. No SEO expert can do it. Not even Chuck Norris can do it. It's nonsensical.

 

Let's say I had this URL:

https://mysite.com/paris

Tell me: Is that a category or a post? You don't know, right? Well, then how on earth is Apache supposed to know?

 

Apache has to be able to distinguish between categories and posts. You need two different URL patterns. For example, posts could be subresources of categories:

https://yoursite.com/some-category/some-post

Or you could have two entirely separate paths:

https://yoursite.com/categories/some-category
https://yoursite.com/posts/some-post

Whatever you do, the URLs of categories and paths must be distinguishable.

ok i did it like u guys told me to :) its fixed now

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.