HTACCESS - how do you point to another URL with /?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - how do you point to another URL with /?

Post by simonmlewis »

There will be approx 150 of them. The problem is, we use to use that ip_mobilehome page to point people to a mobile or desktop version of a web site. But the site is now responsive, so we don't need that file.

Might be better to just point a permanent 301 for ip_mobilehome.php straight to the full homeurl, and leave it at that.
But I thought it's better for google (errors) to say "this is actually where it is now pointing"....?!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - how do you point to another URL with /?

Post by simonmlewis »

Also, our Wordpress blog has errors like this:

[text]http://www.site.co.uk/blog/2014/07/URL[/text]
I want to push all that have URL at the end, to point them to the homepage.

This is our current Blog HTACCESS file they write and provide. I don't think I can fix it from the higher level HTACCESS.

Code: Select all

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

</IfModule>

# END WordPress
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - how do you point to another URL with /?

Post by Celauran »

simonmlewis wrote:Also, our Wordpress blog has errors like this:
Errors like what?
simonmlewis wrote:[text]http://www.site.co.uk/blog/2014/07/URL[/text]
Is URL a literal or a variable?

simonmlewis wrote:I don't think I can fix it from the higher level HTACCESS.
I suspect you may have to.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - how do you point to another URL with /?

Post by simonmlewis »

Well that is the error, tho i admit to you it's nothing.
Google Webmasters has picked it up as an error URL, so it goes to one of their OOOPS pages.
How would I fix it from a higher level if I cannot do it via the Word PRess HTACCESS?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - how do you point to another URL with /?

Post by simonmlewis »

Why won't this take a URL like this: /childrens-items/girls and point it to childrens-items-girls?

Code: Select all

RewriteRule ^childrens-items/girls(.*)/? /childrens-items-girls [L,R=301,L]
It's a new site we have taken over, but they have older URLs. Maybe have similar front parts of the URLs, like:
http://www.site.co.uk/childrens-items/g ... en-display

So we want all that are childrens-items/girls/*** to go to childrens-items-girls, and the same for the boys one.

Whole of it:

Code: Select all

DirectoryIndex index.html index.htm index.php
order allow,deny
allow from all 

RewriteEngine On
Options +FollowSymLinks
Options +Indexes

RewriteRule ^(blog)($|/) - [L]
RewriteRule ^childrens-items/girls(.*)/? /childrens-items-girls [L,R=301,L]


RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2 [QSA]
RewriteRule ^categ/([0-9]+) /index.php?page=categ&c=$1 [QSA]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=categ&c=$1&cname=$2&pagenum=$3 [L]

RewriteRule ^product/([0-9]+)/([^/]+)/([^/]+)/([^/]+) /index.php?page=product&c=$1&category=$2&id=$3&h=$4 [QSA]

RewriteRule ^productsall/([0-9]+)/ /index.php?page=productsall&pagenum=$1/ [L]

RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]


RewriteRule ^$ index.php?page=home [L]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - how do you point to another URL with /?

Post by Celauran »

simonmlewis wrote:Why won't this take a URL like this: /childrens-items/girls and point it to childrens-items-girls?

Code: Select all

RewriteRule ^childrens-items/girls(.*)/? /childrens-items-girls [L,R=301,L]
Duplicated L notwithstanding -- and get rid of R=301 until you get the rewrite working -- it absolutely should. What's happening?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - how do you point to another URL with /?

Post by simonmlewis »

Goodness me, I wish sometimes I cleared cache and site prefs in firefox. It works now!! lol.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: HTACCESS - how do you point to another URL with /?

Post by Celauran »

I use Firefox Developer Edition set to delete cache, history, cookies, etc on close. Basically always runs in private mode and I use it only for development. Never need to worry about caches not clearing.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - how do you point to another URL with /?

Post by simonmlewis »

Thanks a lot. Now installing that.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply