Jump to content

Recommended Posts

Hi,

 

I've been having problems with my seo friendly links. I was wondering if anyone could help at all?

 

Options +FollowSymLinks
RewriteEngine On

RewriteRule photos/([a-zA-z]+)\.html$ photos.php?view=$1
RewriteRule artwork/([a-zA-z]+)\.html$ artwork.php?view=$1
RewriteRule ([a-zA-z]+)\.html$ index.php?page=$1

RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2
RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2&pid=$3
RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2
RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3

 

The top five lines are fine, its the bottom four which are causing me problems..

Whichever two lines (artwork or photos) are last are the ones that work. I know I can put a ^ at the beginning, but this doesn't seem to work.

Any help would be hugely helpful!

Many thanks

E

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/
Share on other sites

You have the same rewrite rules for different files! Prefix them with something to make them different.

RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2
RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2

i.e.

RewriteRule ^artwork/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2
RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2

 

Change the urls so they match the rules. Also dont start a rewrite using

([a-zA-z0-9]+)

As it allows any alphanumeric text it clashes with your other rules. Again, prefix with a string of meaning as above.

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054145
Share on other sites

Thats still not working unfortunately!

It just makes it come up with 404 not found?

Any ideas?

On its own it should be like this:

 

ie:

photos.php?name=text&cid=1&pid=1

artwork.php?name=text&cid=1&pid=1

 

and the same but without the pid at the end.

I'm a bit stuck!

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054180
Share on other sites

You have added an extra paramater on the end, that is why! (pid)

 

Here is the correct rule

RewriteRule ^photos/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3

photos.php?name=text&cid=1&pid=1

 

Will become

 

http://www.domain.com/photos/text/1/1.html

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054486
Share on other sites

Its still not working?

Am I missing something?

 

Here is my complete .htaccess file:

 

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule photos/([a-zA-z]+)\.html$ photos.php?view=$1
RewriteRule artwork/([a-zA-z]+)\.html$ artwork.php?view=$1
RewriteRule ([a-zA-z]+)\.html$ index.php?page=$1

RewriteRule ^artwork([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2
RewriteRule ^artwork/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)\.html$ artwork.php?name=$1&cid=$2&pid=$3
RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2
RewriteRule ^photos/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3

 

Any help would be amazing! thanks!

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054493
Share on other sites

The url i'm typing is:

 

http://localhost:8888/website/photos/personal/6.html

 

The actual hard link is:

 

http://localhost:8888/website/photos.php?name=personal&cid=6

 

I have two sections: Artwork & photos

They do the same job just with different content, however they are just separated by the files.

 

all of the files:

 

artwork.php

photos.php

index.php

 

are located just in the /website folder where the .htaccess is.

It works with just 'photos' or just 'artwork' but not together.

 

Thanks, E

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054501
Share on other sites

Ok, given that information I believe your RewriteBase should actually be...

 

RewriteBase /website/

 

One technique I always use for testing is to add the [R=302] flag to the end of a rule I'm testing, this will actually redirect the browser so you will see in the address bar what URL Apache is serving, this normally gives a good indication what went wrong. Once you get the right page you can remove the flag.

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054514
Share on other sites

I think that last line helped, however its still not working.

Does the [R=302] tag mean that it should show the hard link?

 

Options +FollowSymLinks
RewriteEngine On
RewriteBase /website/ 
RewriteRule ^photos/([a-zA-z]+)\.html$ photos.php?view=$1 [R=302]
RewriteRule ^artwork/([a-zA-z]+)\.html$ artwork.php?view=$1 [R=302]
RewriteRule ^([a-zA-z]+)\.html$ index.php?page=$1 [R=302]
RewriteRule ^artwork/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2 [R=302]
RewriteRule ^artwork/([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2&pid=$3 [R=302]
RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2 [R=302]
RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3 [R=302] 

 

It comes up with 404 on both photos & artwork.

If I remove the ^photos/ or ^artwork/ then it will work for that page, but if I remove both, it will only work on the one that is on the last line (Hope that makes sense!)

Any other ideas?

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054524
Share on other sites

R=302 is a temporary redirect so yes, whatever is in the browser address bar is the page apache is trying to serve up, so yes, the 'hard link' as you put it. I've just realised all your patterns is a-zA-z, this is likely causing problems (notice the lower case z). Fixing that could easily make a big difference to behaviour.

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054543
Share on other sites

Finally!

Thankyou for your help. I managed to figure out the problem. I realized that it was down to my seo links including '-' inbetween words. Obviously this wasn't including them, so was 404ing. I changed it to ([a-zA-Z0-9^-]+) and it works brilliantly!

Thankyou all who helped!

Link to comment
https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054554
Share on other sites

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.