Forum Moderators: phranque

Message Too Old, No Replies

Url rewrite

Change internal urls with htaccess

         

TheKiller

3:17 pm on Mar 4, 2015 (gmt 0)

10+ Year Member



I seek to rewrite my forum urls from :
http:// localhost/forums/app.php/page/zombielinks

Into this format:
http:// localhost/forums/zombielinks.php

Could someone please help me with some snippet to do this? :)

lucy24

5:22 pm on Mar 4, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What have you tried so far? It looks like you've been around long enough to know that this subforum takes the "teach a man to fish" approach. So first show us what you've tried, and what the consequences were.

You'll also need to explain what you're trying to do without using the word "rewrite" because it so often gets misinterpreted. Explain #1 what you want the user's address bar to say and #2 where the content really lives.

It looks as if your visible URL is
/forums/app.php/page/zombielinks
and you want to serve content from
/forums/zombielinks.php
... but that obviously makes no sense, because why would anyone want an URL like that? Did you really mean redirect?

TheKiller

8:18 pm on Mar 4, 2015 (gmt 0)

10+ Year Member



I didnt try anything yet. I did in the past and i didnt get it. I thought i might stumble someone that knows how to do this in a hearth beat. I meant to do exactly what i asked.

The contents are on /forums/app.php/page/zombielinks and thats what shows in the address bar.

I want to change to /forums/zombielinks.php

So remove app.php/page/ and add the .php extension at the end.


Looked around and this should do it, but it doesnt seem to.


RewriteEngine On
RewriteRule ^forums/zombielinks\.php$ /forums/app.php/page/zombielinks [L]

not2easy

8:52 pm on Mar 4, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It might help to look at the basics, a very old post that is still helpful to understand how to get from point A to point B and knowing just what you want can (or can't) be done: [webmasterworld.com...]
Also very useful if dated are links in the Library and Charter just above the Forum Name at the top of the page.

The rule you have here seems to be in reversed order.

lucy24

9:39 pm on Mar 4, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Looked around and this should do it, but it doesnt seem to.

RewriteEngine On
RewriteRule ^forums/zombielinks\.php$ /forums/app.php/page/zombielinks [L]

What this rule does:

If user makes a request for
example.com/forums/zombielinks.php

then don't change the address bar, but show them the content that lives at
example.com/forums/app.php/page/zombielinks

... which can't possibly be a real, physical file. Sure, it is theoretically possible to have a directory called /app.php/-- but what comes after that? When you're rewriting, you expect to see a full filename including extension.

That's why I stress putting things in terms of what the address bar says or should say, and where the content physically lives.

TheKiller

9:48 pm on Mar 4, 2015 (gmt 0)

10+ Year Member



Running this seems to remove the app.php


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]

But how can i make it remove the /page too and add .php?

TheKiller

9:57 pm on Mar 4, 2015 (gmt 0)

10+ Year Member



Lucy, the phpbb software generates the links as
example.com/forums/app.php/page/zombielinks

It doesnt have to be a physical file and i didnt say it is. Its just a working url that needs to change. I only need to change them to the format i have mentioned twice. I think i am being explicit.. Am i still confusing you? :-\

lucy24

4:55 am on Mar 5, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It doesnt have to be a physical file and i didnt say it is.

Actually, you did. Or rather your rule did. See, I don't want to come right out and say "You have misunderstood everything and your rules are all backward" if there is some other explanation.

I think i am being explicit.

I've no doubt you do.

Running this seems to remove the app.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]
But how can i make it remove the /page too and add .php?

This rule has no effect on the visible URL. What it says is:
If the user requests any file that doesn't physically exist-- which the server has to check for on every request, regardless of extension-- then serve content from-- we hope--
example.com/app.php
retaining the original query string. (This flag is actually unnecessary, since that's the default behavior.) I said "we hope" because the target of the rule doesn't begin in a / slash, so we're relying on a RewriteBase directive somewhere earlier in the same htaccess.

So... Do you want to keep those weird URLs with /app.php/ in the middle, or do you want to redirect to a different URL? And if you do want to redirect, have you taken steps to ensure that your CMS generates different links in the future? Neither browsers nor search engines will be happy if a site's internal links point straight to a redirect.

Or do you simply want to do the opposite of what the original rule said, replacing
RewriteRule ^forums/zombielinks\.php$ /forums/app.php/page/zombielinks [L]

with its mirror-image
RewriteRule ^forums/app.php/page/zombielinks /forums/zombielinks\.php$ [L]

?

I have to say that the latter seems a little more plausible, assuming /forums/zombielinks.php is a real, physical file that already exists.