Page 1 of 2

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

Posted: Fri Oct 31, 2014 5:22 am
by simonmlewis
We have many URLs that are dead, since they have "/mobile" at the start.
I know how to point one URL to another. But how do I point one URL that "starts" with '/mobile' to another?

ie

RewriteRule ^mobile/...../?$ /blog [QSA]

??

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

Posted: Fri Oct 31, 2014 7:12 am
by Celauran
Just capture the rest of the URL and do whatever you need to with it. This will strip out the mobile/ and leave the rest, for example. mobile/path/to/page would become path/to/page.

Code: Select all

RewriteRule ^mobile/(.*) $1 [L,QSA]

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

Posted: Fri Oct 31, 2014 7:43 am
by simonmlewis
So if the url is:
[text]http://www.simon.co.uk/mobile/product/5 ... 5X51-SUPER[/text]

Code: Select all

RewriteRule ^mobile/(.*) /home [L,QSA]
Then it would point it to whatever URL I want, such as homepage, as it sees the 'mobile' in there?

RewriteRule ^mobile/(.*) $1 [L,QSA]

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

Posted: Fri Oct 31, 2014 8:16 am
by Celauran

Code: Select all

RewriteRule ^mobile/(.*) /home [L,QSA]
This would ignore everything after mobile and redirect to /home

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

Posted: Fri Oct 31, 2014 8:43 am
by simonmlewis
How can the same be done if it starts like this:

[text]http://www.test.co.uk/ip_mobilehome.php?url=http://............[/text]

How would I do a 301 for all ip_mobilehome ?

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

Posted: Fri Oct 31, 2014 10:00 am
by Celauran
What's the url= bit? Do you even need to do that via .htaccess?

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

Posted: Fri Oct 31, 2014 10:05 am
by simonmlewis
I don't know. It use to be used to take someone to ip_mobilehome.php, and then query their device before taking them to the relevant web page thru a PHP file.
I just wondered if I could do a 301 via HTACCESS for it.

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

Posted: Mon Dec 01, 2014 5:25 am
by simonmlewis
Hi.
We still have this problem. with URLs like the one I mentioned.
I want to be able to point each one to the relevant product or category page.
So how do you do something like this:

Code: Select all

RewriteRule ^ip_mobilehome.php?url=http://www.site.co.uk/services?$  /services [QSA]
As that doesn't work.

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

Posted: Mon Dec 01, 2014 7:56 am
by Celauran
Something like this, maybe?

Code: Select all

RewriteCond %{REQUEST_URI} ip_mobilehome.php
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/(.*)&?
RewriteRule (.*) %1? [L]
Actual examples of inputs and their intended destinations would make this easier.

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

Posted: Mon Dec 01, 2014 8:02 am
by simonmlewis
If you'll igore the site.co.uk, that is an actual line I need to replace.
I have about 150 of them, so do I need to do those three lines you've shown, for each line? Or is there a shortened version, for each of the 150 ?

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

Posted: Mon Dec 01, 2014 8:04 am
by Celauran
What this rule set is doing is checking if the page requested is ip_mobilehome.php, if the query string contains url=whatever, stripping the domain name, capturing the rest, and redirecting there.

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

Posted: Mon Dec 01, 2014 8:09 am
by simonmlewis
So what if "the rest" is inaccurate too, and we need to take them to a more appropriate URL?
So sometimes we might take them to /services, but otherwise it might be an old category URL that we need to take them to a new one.

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

Posted: Mon Dec 01, 2014 8:10 am
by Celauran
Then .htaccess probably isn't the right tool for the job.

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

Posted: Mon Dec 01, 2014 9:07 am
by simonmlewis
So if I want to point that long URL to another completely different internal URL, ie... /services should go to /newservices, I cannot do that in HTACCESS?

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

Posted: Mon Dec 01, 2014 9:20 am
by Celauran
Of course you can. Whether or not you should depends on how many cases you're dealing with and how complex the logic is going to be. If you're mostly redirecting to the url= URL with a few exceptions, sure. You just don't necessarily want to end up with hundreds of rewrite rules.