HTACCESS - how do you point to another URL with /?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
HTACCESS - how do you point to another URL with /?
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]
??
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]
??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - how do you point to another URL with /?
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]-
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 /?
So if the url is:
[text]http://www.simon.co.uk/mobile/product/5 ... 5X51-SUPER[/text]
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]
[text]http://www.simon.co.uk/mobile/product/5 ... 5X51-SUPER[/text]
Code: Select all
RewriteRule ^mobile/(.*) /home [L,QSA]RewriteRule ^mobile/(.*) $1 [L,QSA]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - how do you point to another URL with /?
Code: Select all
RewriteRule ^mobile/(.*) /home [L,QSA]-
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 /?
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 ?
[text]http://www.test.co.uk/ip_mobilehome.php?url=http://............[/text]
How would I do a 301 for all ip_mobilehome ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - how do you point to another URL with /?
What's the url= bit? Do you even need to do that via .htaccess?
-
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 /?
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.
I just wondered if I could do a 301 via HTACCESS for it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
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 /?
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:
As that doesn't work.
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]Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - how do you point to another URL with /?
Something like this, maybe?
Actual examples of inputs and their intended destinations would make this easier.
Code: Select all
RewriteCond %{REQUEST_URI} ip_mobilehome.php
RewriteCond %{QUERY_STRING} ^url=http://www.site.co.uk/(.*)&?
RewriteRule (.*) %1? [L]-
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 /?
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 ?
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 ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - how do you point to another URL with /?
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.
-
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 /?
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.
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - how do you point to another URL with /?
Then .htaccess probably isn't the right tool for the job.
-
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 /?
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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: HTACCESS - how do you point to another URL with /?
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.