html to php to wordpress-help mod rewriting all links please

Discuss practical ways rearrange URLs using mod_rewrite.

html to php to wordpress-help mod rewriting all links please

Postby burgers » Tue Oct 06, 2009 7:11 am

Hi, I've been looking through the forums but can't seem to find a solution for this. I would really appreciate some help.

I had an html site and later converted to php, so had to rewrite the htaccess to pull in all my old links around the web to their new .php names.

I have now changed this .php site to a wordpress site. I have kept all the same page name urls, but all the links now end in / and have no extentions as is the norm with w.p sites.
Obviously now all my previous external web links don't work.

So I would now like to pull in all .php and .html links around the web so they take visitors to the equivalent new wordpress pages.

i.e pull in www.????.com/page.html and www.????.com/page.php
to www.????.com/page/

But because of what I have in the htaccess already ie. html to php...and a cloaked links mod and the code wordpress has placed in my htaccess file, I can't seem to make this work, and I don't want to screw anything else up.

I'm on apache and linux

here is my .htaccess as it stands.


RewriteEngine On
RewriteRule ^link/([/_0-9a-zA-Z-]+)$ link.php?id=$1

RewriteRule (.*)\.html$ http://www.mysite.co.uk/$1.php [R=301,NC,L]


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

# END WordPress

Thanks
Last edited by burgers on Tue Oct 06, 2009 11:50 am, edited 1 time in total.
burgers
 
Posts: 10
Joined: Tue Oct 06, 2009 6:11 am

Postby richardk » Tue Oct 06, 2009 10:29 am

Try
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^(.+)\.html$ http://www.streetmusician.co.uk/$1/ [NC,R=301,L]

  # Don't match internal sub requests (eg. to /index.php).
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteRule ^(.+)\.php$ http://www.streetmusician.co.uk/$1/ [NC,R=301,L]

  RewriteRule ^link/([-/_0-9a-zA-Z]+)$ /link.php?id=$1 [QSA,L]

  # BEGIN WordPress
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule . /index.php [L]
  # END WordPress
</IfModule>

You may also need to exempt the Wordpress directory(s) from the redirect by adding
Code: Select all
  RewriteCond %{REQUEST_URI} !^/(dir1|dir2)(/.*)?$ [NC]

after
Code: Select all
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby burgers » Tue Oct 06, 2009 11:45 am

My god...it works ! ..and so do the affiliate links.

Thank you so much.

You surely are the greatest coder that ever lived !

My site is now back on line and you've made my day.

Thanks again. :D :D 8)
burgers
 
Posts: 10
Joined: Tue Oct 06, 2009 6:11 am

Postby burgers » Tue Oct 06, 2009 12:12 pm

Ooops ! bit premature..

Can't seem to log in now... I think there needs to be exceptions for everything in admin...

eg

http://www.mysite.co.uk/wp-admin/index.php

http://www.mysite.co.uk/wp-admin/widgets.php

http://www.mysite.co.uk/wp-admin/plugin ... tus=active

http://www.mysite.co.uk/wp-admin/media. ... ent_id=875

etc..

any more ideas ?

:D
burgers
 
Posts: 10
Joined: Tue Oct 06, 2009 6:11 am

Postby richardk » Tue Oct 06, 2009 12:42 pm

Did you try exempting the whole directory?
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^(.+)\.html$ http://www.streetmusician.co.uk/$1/ [NC,R=301,L]

  # Don't match internal sub requests (eg. to /index.php).
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteCond %{REQUEST_URI} !^/(wp-admin)(/.*)?$ [NC]
  RewriteRule ^(.+)\.php$ http://www.streetmusician.co.uk/$1/ [NC,R=301,L]

  RewriteRule ^link/([-/_0-9a-zA-Z]+)$ /link.php?id=$1 [QSA,L]

  # BEGIN WordPress
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule . /index.php [L]
  # END WordPress
</IfModule>

You may need to clear your browser's cache.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby burgers » Tue Oct 06, 2009 1:34 pm

Hi, thanks for replying..

I exempted the directory previously and this time cleared the cache with cc cleaner. Still no luck.

Can't get passed the login page... (without changing back)

.i.e.

http://www.mysite.co.uk/wp-login/

http://www.mysite.co.uk/wp-login.php

However, once I'm in the admin (using my htac) , if I change the htaccess to your file, i can move around admin, visit the site, go back and forth to the site and admin with out a problem. But once i log out, i can't get back in.

?
burgers
 
Posts: 10
Joined: Tue Oct 06, 2009 6:11 am

Postby burgers » Wed Oct 07, 2009 7:24 am

Hi, is there any chance of a little more help as i've been experimenting all day with this and still can't make this work with the login.

I've not got a clue with code and am probably doing something really simple but totally wrong.

I'm still not sure how to expempt all wordpress directories using the code above.

Do i use

RewriteCond %{REQUEST_URI} !^/(wp-login)(/.*)?$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-admin)(/.*)?$ [NC]

or

RewriteCond %{REQUEST_URI} !^/(wp-login|wp-admin)(/.*)?$ [NC]

or something else ?

I'm up the creek without it.

Thanks
burgers
 
Posts: 10
Joined: Tue Oct 06, 2009 6:11 am

Postby richardk » Wed Oct 07, 2009 11:49 am

A little patience?

Is /wp-login.php an existing PHP file? Try
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^(.+)\.html$ http://www.streetmusician.co.uk/$1/ [NC,R=301,L]

  # Don't match internal sub requests (eg. to /index.php).
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  # Don't continue for /wp-login.php
  RewriteCond %{REQUEST_URI} !^/(wp-login)\.php$ [NC]
  # Don't continue for /wp-admin/*
  RewriteCond %{REQUEST_URI} !^/(wp-admin)(/.*)?$ [NC]
  RewriteRule ^(.+)\.php$ http://www.streetmusician.co.uk/$1/ [NC,R=301,L]

  RewriteRule ^link/([-/_0-9a-zA-Z]+)$ /link.php?id=$1 [QSA,L]

  # BEGIN WordPress
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule . /index.php [L]
  # END WordPress
</IfModule>

Are there lots of PHP files that the reidrect should not redirect? You could replace
Code: Select all
  # Don't continue for /wp-login.php
  RewriteCond %{REQUEST_URI} !^/(wp-login)\.php$ [NC]
  # Don't continue for /wp-admin/*
  RewriteCond %{REQUEST_URI} !^/(wp-admin)(/.*)?$ [NC]

with
Code: Select all
  # Don't continue for /wp-admin/*
  RewriteCond %{REQUEST_URI} !^/(wp-admin)(/.*)?$ [NC]
  # Don't continue for an existing (.php) file.
  RewriteCond %{SCRIPT_FILENAME} !-f
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby burgers » Wed Oct 07, 2009 4:07 pm

That's great Richard, the first option works perfectly.

You've made my world a happy place again. For a moment I thought all was lost.

I can't thank you enough. I will link to this forum as an invaluable resource for web design.

Cheers !

:D :D
burgers
 
Posts: 10
Joined: Tue Oct 06, 2009 6:11 am

Postby burgers » Sun Oct 18, 2009 10:24 am

Hi there, back again.

The fix has been working really well over the last couple of weeks and I've been very happy with it, but I have found something else that I think may need another exception.

When writing a post, the wordpress spell checker won't seem to work and gives the message 'Could not get raw post data' when clicked.

I'm assuming this has something to do with the ht fix and wondered if you could possibly add a little more code to let this through.

Your help is greatly appreciated as always.
burgers
 
Posts: 10
Joined: Tue Oct 06, 2009 6:11 am

Next

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron