Welcome to WebmasterWorld Guest from 35.153.73.72

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

changing file names via htaccess

I want to retain old urls

     
5:06 pm on Feb 14, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 5, 2002
posts:1382
votes: 0


Hi
I have a website which I want to convert to Wordpress (various reasons including client wishes). I want to keep the content as stable as possible and also keep the current file names which look like www.example.com/widgets/blue-widget.php as the ranking is very good. I understand some Seo guys may disagree, but my gut feeling is to try and keep the urls the same for now. The webmaster I'm using says wordpress will produce file names like www.example.com/widgets/blue-widget/ and there is no way to change this. I assumed htaccess would achieve what I want and we could force all navigation links within the site to be in the original format.

I suggested the following in htaccess (normal wordpress stuff then my line at the bottom) but it does not appear to work.... any help appreciated.

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

# END WordPress


RewriteRule ^widget/([^/\.]+).php$ widget/$1/
5:16 pm on Feb 14, 2017 (gmt 0)

Moderator This Forum from US 

WebmasterWorld Administrator travelin_cat is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Feb 28, 2004
posts: 3289
votes: 16


"The webmaster I'm using says wordpress will produce file names like www.example.com/widgets/blue-widget/ and there is no way to change this."

This is not true. You can edit urls.

To edit the page/post url go to the "Permalink" on the top of the page and click "edit".
6:18 pm on Feb 14, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 5, 2002
posts:1382
votes: 0


Thanks Travelin Cat

So Permalink can be edited to produce www.example.com/widgets/blue-widget.php rather than the default www.example.com/widgets/blue-widget/
I assume it writes something to htaccess?
6:23 pm on Feb 14, 2017 (gmt 0)

Moderator This Forum from US 

WebmasterWorld Administrator travelin_cat is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Feb 28, 2004
posts: 3289
votes: 16


All that is doing is changing the link address, it is not posting to htaccess. Also, I do not believe that you can append .php to a wordpress url.
7:00 pm on Feb 14, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 5, 2002
posts:1382
votes: 0


If wordpress cannot append .php, then is it possible to add something to htaccess to let all the old urls continue to be used?

I simple want www.example.com/widgets/blue-widget.php to work (and remain in the google index).
7:46 pm on Feb 14, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15699
votes: 810


If wordpress cannot append .php, then is it possible to add something to htaccess to let all the old urls continue to be used?

Yes, absolutely. Basically you'll be rewriting twice. Your added rules have to come before the part WP creates. Say you have an established URL
/pagename.php
but if you let WP do its thing, the page content would come out as
/pagename/

Then you make a rule
RewriteRule ^pagename\.php /pagename/ [L]
If you have a bunch of names getting changed in the same way, it would be
RewriteRule ^(onepage|otherpage|thirdpage)\.php /$1/ [L]
These new, rewritten URLs will in turn be passed along to WP, which will handle them just as if the user had requested the /pagename/ form in the first place.

Watch out, though. If you've firmly decided you don't want to change URLs, keep track of your logs and make sure nobody is requesting /pagename/ like that. (Especially be alert for Google, which likes to experiment.) If it starts to happen, you'll need one more rule. But don't bother about it unless you see it.
8:29 pm on Feb 14, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 5, 2002
posts:1382
votes: 0


Thanks Lucy

My webmaster is concerned of creating any complexity which may cause conflicts with future WP updates. However, I think this solution should not cause any problems. The intention is to run this for a few months and once google is happy with the new ip and page design we can look at changing the page urls to normal WP ones.

So, do you think this will work (I've put the rewrite at the beginning as you suggest). The rewrite rule I've used should be good for all the various pages and effectively just replace .php with a forward slash.

RewriteRule ^widget/([^/\.]+).php$ widget/$1/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /seedum/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /seedum/index.php [L]
</IfModule>

# END WordPress
3:46 am on Feb 15, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15699
votes: 810


RewriteRule ^widget/([^/\.]+).php$ widget/$1/

Yes, that should do nicely except that you MUST end with the [L] flag and you SHOULD start the target with /

Note that you don't need to escape . (literal periods) inside grouping brackes--though it isn't a lethal error--but you do need to escape them elsewhere. So the pattern is
^widget/([^/.]+)\.php$
though personally I like
^widget/(\w+)\.php$
at a savings of three bytes, assuming the URLs don't contain hyphens. (Possibly they do, since WP does love its hyphens.)

SO, for example,
RewriteRule ^widget/([^/.]+)\.php$ /widget/$1/ [L]
3:38 pm on Feb 15, 2017 (gmt 0)

Preferred Member from CA 

Top Contributors Of The Month

joined:Feb 7, 2017
posts: 552
votes: 54


Search engines are super efficient with WP indexing. A reindexing of your site would not take much time. You can do this manually with Google Webmaster tools. With Bing you can use your RSS feed. both Google and Bing are very aggressive with their indexing, so no worries.

I'm sure you can tweak your htaccess and get it to work, but maintaining it might be a lot more work. I'd just let WP do its thing. Code changes, if you need them in the future, might be more complex. Simple is more reliable. WP only has a set number of options in permalinks:

Common settings 
Check one of the radio buttons corresponding to the correct Permalink Structure for your blog.

Default - An example of the default structure is http://www.sample.com/?p=123

Day and name - An example of the day and name based structure is http://www.sample.com/2008/03/31/sample-post/

Month and name - An example of the month and name based structure is http://www.sample.com/2008/03/sample-post/

Numeric - An example of the numeric structure is http://www.sample.com/archives/123

Post name - An example of the post name structure is http://www.sample.com/sample-post

Custom structure - In the box specify the custom structure you desire to use. One example is /archives/%year%/%monthnum%/%day%/%postname%/. Look at the Using Permalinks article for further discussion of Permalink Structure Tags.
10:15 am on Feb 16, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 5, 2002
posts:1382
votes: 0


Thanks Lucy and TorontoBoy for helping me. Much appreciated.

My concern is that we are changing server, IP, layout and now page urls on a site that ranks well. I'm a bit out of date with Seo but in the old days that would have rung alarm bells. Also I don't like the theory that 301's lose 15% of PR or is this also now no longer a concern?

So.... the reason for updating to WP has many pluses and maybe we just have to bite the bullet and hope all will be OK.
4:08 pm on Feb 16, 2017 (gmt 0)

Preferred Member from CA 

Top Contributors Of The Month

joined:Feb 7, 2017
posts: 552
votes: 54


A month ago I moved a Drupal site (actually rewrote to D8 from D6) to a new host provider, copy/pasted over docs and let 'er rip. Google and Bing did not even skip a beat. After a week they were caught up. The other search engines are not as smart. Sogou is still trying to index my old site URLs, which obviously are not there. Site migrations are common and the smart search engines know this.

The radical URL rewrite method also has the benefit that if there were scraper, referrer, malicious bots hitting the old URLs they will be very obvious on your raw access log, as they will receive 404s. You can then ban them.