1

I've read a lot of similar questions but none of them seem to work for me or be applicable.

I have a Wordpress site that I'm currently running on localhost for development.

This is the contents of it:

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

/* The lines added by me */
RewriteEngine On
Redirect 301 /wordpress/about/ /wordpress/about/history/

</IfModule>
# END WordPress

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300

The two lines were added by me to redirect my empty About page to its sub-page History, as recommended here.

However, when I then reload the server and go to localhost/wordpress/about/ in Firefox, I get the following screen:

enter image description here

Note the tons of extra "history" links appended to the URL. What could be causing this?

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68

1 Answers1

1

Have it like this in /wordpress/.htaccess:

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300

RewriteEngine On
RewriteBase /wordpress/

RewriteRule ^about/?$ /wordpress/about/history/ [L,NC,R=301]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Make sure to completely clear browser cache or test if from a new browser.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Perfect, thank you! Would never have been able to figure this out, so I'm glad I asked. I changed the order of the rules to move `/about/history` rewrite rule to the very bottom, but it all works. One minor thing - while `localhost/wordpress/about` redirects perfectly, adding a slash at the end of about results in a 404. Is there any chance of being able to redirect that case too using the above RewriteRules? – Hashim Aziz Aug 06 '19 at 18:23
  • No, `localhost/wordpress/about` redirects as it should, but `localhost/wordpress/about/` (note the trailing slash) causes a 404. Is there any way to make that redirect in the same way? – Hashim Aziz Aug 06 '19 at 18:44
  • 1
    Never mind, it's now working. It seems that two things were getting in my way: 1) I didn't realise the order of the RewriteRules mattered, 2) browser caching, which has never been a problem in all the months I've been coding on this site, so I didn't expect it. Resolving both of those solved the issue. Might just start developing with cache turned off from now on. Thanks for your help! – Hashim Aziz Aug 06 '19 at 19:03
  • I'm having trouble adapting this .htaccess file for the same site in production. This is the .htaccess file you recommended, adapting by me for production: https://pastebin.com/99mKVK9M. The moment I replace the default production .htacess file with this one, the entire site starts returning Error 500s. Any ideas what could be wrong with it? Would really appreciate the help. – Hashim Aziz Aug 14 '19 at 02:05
  • no, everything is inside a `public_html` folder, which itself is inside the domain name folder. – Hashim Aziz Aug 14 '19 at 17:26
  • No such luck. Here is what I currently have: https://pastebin.com/TiJzU6Jg. – Hashim Aziz Aug 14 '19 at 18:00
  • oh ok, if `index.php` also exists in `www.mydomain.com` directory then you do need `RewriteBase www.mydomain.com` – anubhava Aug 14 '19 at 18:12
  • No, `index.php` is also in `public_root`, but changing the RewriteRule from `www.mydomain.com/about/history/` to "/about/history/" doesn't make a difference either. Still returns Internal Server Error 500. – Hashim Aziz Aug 14 '19 at 18:23
  • Can you please open a new question with this 500 problem. Let's take it up there rather than adding lot of comments here. – anubhava Aug 14 '19 at 19:29
  • No problem, [done here](https://stackoverflow.com/questions/57502022/error-500-when-changing-htaccess-file-on-production-server). – Hashim Aziz Aug 14 '19 at 21:05