Forum Moderators: phranque
I am redesigning a site at the moment and I am looking a lot at SEO. At the moment all the products are viewed by the following fashion.
[domain.com...] etc
I am wanting to use .htaccess to produce the following...
[domain.com...]
[domain.com...] etc...
I am getting nowhere with this. Can anyone shed some light on it?
Thanks in advance!
Jim
1) Change the links on your pages to 'friendly links'.
2) Internally rewrite those friendly URLs, when requested by a client, into the form needed for your script.
3) Externally redirect dynamic ('unfriendly') URLs to the new friendly ones if directly-requested by a client (i.e. browsers and search engine spiders).
"It doesn't work" gives us no hint as to what the problem might be. How did you test? What were the results? How did those results differ from expectations?
Jim
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*)products/(.*)$ $1products/products.php?id=$2
I have this .htaccess file in the following directory...
[domain.com...]
I am calling it by the following URL...
[domain.com...]
(which i want to point to [domain.com...]
Is it possible or am I just being thick!?
Assuming you have rewritten all your page links into the friendly forms, you do an internal rewrite and then an external redirect.
# Internally rewrite static URLs to dynamic
RewriteRule ^products/(.+)$ /products.php?id=$1 [L]
# Externally redirect dynamic to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /products\.php\?id=(.+)\ HTTP/ [NC]
RewriteRule ^products\.php$ http://www.example.com/products/%1 [R=301,L]
Not knowing you don't use the querry string on the first half of the last rewrite rule above was my stumbling block. We newbies have no way of knowing that. It just seems logical to put the querry string there when you do on the rewrite condition. Hope Jim will add a note in his tutorial about that querry string. I am sure it will help many others.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^.]+)$ [mydomain.com...] [L]
and it does the followin....
if i goto the following url....
[mydomain.com...]
directs the user to the following....
[mydomain.com...]
The only problem I have is that in the address bar the full url appears. I was under the impression that I could get it to display the URL in the address bar as [mydomain.com...] and not [mydomain.com...]
Does anyone know if this is possible?
If i use - RewriteRule ^([^.]+)$ products.php?id=$1 [L] - then I get a 403 error?
any ideas why?
Thank you for your assistance sc112. Its nice to see someone sharing their knowledge and experience rather than thinking people DONT read other posts and try to help themselves (as well as appearing condescending).
Although I tried to educate myself and did a bit of homework rather than post on a forum and expect people to do the thinking for me, it seems that some other people thought otherwise and posted a link to a post they had put online.
I understand frustrations of some people and answering the same question numerous times can be infuriating (try my job.... my colleagues can try a saints patience), but sometimes people ask for help because they genuinely cant come to the answer they want without a little guidance. In my case, I had a little guidance and I sorted my problem.
If only more people showed your selflessness and helpfulness on forums.