简体   繁体   中英

htaccess RewriteRule under WordPress

A WordPress site under development. The goal is to take what looks like permalinks (but are not), pass the relevant bits to a static page via URL parms.

A direct test of the static pages works (forgive the unfinished output):

http://test.cynical.ws/display-murphy/?cynical_id=_Computing 's_7th_law

The common URL for this page should be:

http://test.cynical.ws/murphyism/_Computing 's_7th_law

The RewriteRule I have in place, but which is failing is:

RewriteRule ^murphyism/(.*)$ display-murphy/?cynical_id=$1

Since the direct access to the static page does not produce an error, I doubt it is a mageling of the single quote mark (and the database from which we look-up content has a lot of kets with single quotes).

I have tried various RewriteRule flags (such as [L]) with no change in behavior.

Here is the entirety of the htaccess file:

RewriteEngine on

RewriteRule ^murphyism/(.*)$ display-murphy/?cynical_id=$1

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

# END WordPress

Regarding RewriteRule, as discussed, use:

RewriteRule ^murphyism/(.*)$ display-murphy/?cynical_id=$1 [NE,R,L] 

The important part here is the NE|noescape since the target URL contains a fragment. You need to use the NE flag to avoid URL escaping issues


Regarding the rewrite without redirect, this requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.

Then, the rewrite should look like this:

Options +FollowSymLinks -MultiViews 
RewriteEngine On
RewriteRule ^murphyism/(.*)$ display-murphy/?cynical_id=$1 [NC,NE,L]

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM