简体   繁体   中英

Rewrite rule in wordpress for wordpress page

I'm running wordpress in my local with "ben.scbw.zec.dev" vhost.

I have created page template to display particular event detail.

http://ben.scbw.zec.dev/event-view?view_event=14

I can access page with above url "event-view" is slug on page and page id = 439 .

Now, I desire to access it with below url.

http://ben.scbw.zec.dev/event-view/this-is-test-event/14/

"this-is-test-event" its fro titel of event any text , i have manage to create URl.

Below is code from my .htaccess

# 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

Above is Standard wordpress crated code and i have added following code.

RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^event-view/([^/]*)/([^/]*)/$ ./index.php?page_id=439&titel=$1&view_event=$2 [L]

here 439 is in page id for "even-view" as i mentioned.

But, I'm not able to access page with " http://ben.scbw.zec.dev/event-view/this-is-test-event/14/ " url. it shows me 404 not found error. I have been trying this for 4-5 day but not able to find solution.

I'm really very Thank full if anyone can help me in this.

First of all, wordpress uses internal RewriteRules to map an url. So you don't have to add an additional RewriteRule-tag to your htaccess. You have to register your query parameter and add rewrite rules to the internal wordpress rewrite engine.

@see https://developer.wordpress.org/reference/classes/wp/add_query_var/ @see https://developer.wordpress.org/reference/classes/wp_rewrite/

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