Is this the correct code? I don’t think this removes all file extensions (I’d like to know how to do that as a blanket piece of code that applies to all pages.)
RewriteEngine On
RewriteRule ^page/([^/]*)\.php$ /archive.php?page=$1 [L]
Can’t try it since pagination isn’t put into play. I’m gathering all my chess pieces at the moment.
As said above I’d also like to know how to remove file extensions (.php) please. Is this the correct code?
Don’t include the start anchor because you have a pseudo directory before page.
I wouldn’t use the leading / in the redirection as that redirects first to the server’s root then to the domain’s DocumentRoot.
The .php in your regex can NEVER be matched by “2”. Delete the .php from the regex.
Assuming your mod_rewrite code is located in the DocumentRoot’s .htaccess, those three changes will enable your code to work.
Second code block:
Nope. That will cause an infinite loop (adding .php after .php until the server gives up.
… BECAUSE, as for removing extensions, this is YOUR job in creating your links. THEN, check that the .php version of the {REQUEST_URI} exists before redirecting. That is included in my tutorial at http://dk.co.nz/seo.
The RewriteEngine on is to take mod_rewrite out of Comment Mode. It only needs to be done ONCE (no need to repeat it unless you use RewriteEngine off in an intervening directive).
The first RewriteRule is fine (read excellent).
The second RewriteRule is LOOPY (as mentioned above). TEST whether $1.php exists before making the redirection!
The third RewriteRule allows page/{null} and the end anchor (the $) is NEVER escaped.
[quote=“RyanReese, post:6, topic:110205, full:true”]
I appear to have it working now. However, I notice as I browse throughout my site, that the extensions aren’t being removed. Why is this?[/quote]
Oh, really?
This is because, as stated above, YOU must create the extensionless links. mod_rewrite’s job (once you get to that level), is to redirect the extensionless link to a file request that Apache can serve. That’s the short version of what’s at http://dk.co.nz/seo.
Still fine - assuming that you’ve ensured that you’re not in Comment Mode.
# Missing RewriteCond is located at http://dk.co.nz/seo
# RewriteEngine on SERIOUSLY? Don't duplicate this (wasted machine cycles).
RewriteRule ^([a-z]+)$ $1.php [L][/code]
You missed the reason for RewriteEngine on in the tutorial (or did I miss that?).
If the second atom is supposed to be a digit, you’ve use someone else’s overkill - and it’s nearly as bad at (.*) Moreover, your optional trailing slash will DESTROY your script’s relative links (for one or the other case). Why not
Test that with the R=301 to confirm that the redriection works then remove it for online use … but make sure that your relative links are relative to the archives/whatever/ directory level.
It looks like it’s working correctly but Apache is not. I’ve seen this and heard of this problem before and the only solution I’m aware of is a RESTART of the Apache server.