Shorten WordPress example.com/deleteme/unique.html

New to mod_rewrite? This is a good place to start.

Shorten WordPress example.com/deleteme/unique.html

Postby an52 » Fri Jul 03, 2009 4:07 am

I want to change my WordPress permalinks from

/%category%/%postname%-%post_id%.html


to

/%postname%-%post_id%.html


My .htaccess looks like this:

Options +FollowSymlinks

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

# END WordPress
Options -Indexes
RewriteRule ^/(.*)/(.*).html$ hxxp://www.example.com/$2.html [r=301,nc]


A typical URL looks like:
hxxp://www.example.com/xxx/test-123.html

I know how to shorten the URL in WordPress but am concerned about indexed URLs in search engines which could take a while to go away.

I'd like incoming requests for it to be redirected to:
hxxp://www.example.com/test-123.html

(hxxp used to make it unclickable)

Suggestions welcome. Thanks.
an52
 
Posts: 2
Joined: Fri Jul 03, 2009 3:47 am
Location: Melbourne, Australia

Postby richardk » Fri Jul 03, 2009 9:25 am

The redirect would have to to go first.

Do you have URLs in the format /something1/something2.html that should not be redirected?

Try
Code: Select all
Options +FollowSymLinks -Indexes

<IfModule mod_rewrite.c>
  RewriteEngine On

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

  # BEGIN WordPress
  RewriteCond %{SCRIPT_FILENAME} !-f
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule . /index.php [L]
  # END WordPress
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby an52 » Fri Jul 03, 2009 4:53 pm

That worked perfectly, thank you! You knew it would work, didn't you?
javascript:emoticon(':D')

I didn't have any conflicting URL structures and I tested all links to make sure they are fine. I also rebuilt the sitemap.xml and submitted it.
an52
 
Posts: 2
Joined: Fri Jul 03, 2009 3:47 am
Location: Melbourne, Australia


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 97 guests

cron