I am creating a website for a radio station and want to make a section of the site for artists and tracks that are played on the radio. I am currently migrating the code I have written to a Wordpress template, and I'm having difficulty replicating the RewriteRules I have created.
I want a user to be able to type:
/music/<artist name here>/
/music/<artist name here>/<track name here>/
And have it rewrite to:
/music/artist.php?artist=<artist name here>
/music/track.php?artist=<artist name here>&track=<track name here>
e.g.:
/music/Red+Hot+Chili+Peppers/
/music/Red+Hot+Chili+Peppers/Californication/
I was able to achieve this using the following .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^music/([^/]*)/?$ /music/artist.php?artist=$1
RewriteRule ^music/([^/]*)/([^/]{1,})/?$ /music/track.php?artist=$1&track=$2
When I switched to Wordpress, I began by trying replicate the artist page first, and have been unable to do so.
Being that the structure of Wordpress is different from a standard directory/file structure, I decided to try two methods:
Rewrite to /music/ for both of the rules, then decide to include either artist.php or track.php in the "music" page, based on the GET parameters.
Redirect to /artist/ or /track/ and have two different pages instead.
I have tried both methods and neither work.
For method 1, this is the code I added to functions.php (only trying the artist rewrite to begin with):
function custom_rewrite() {
add_rewrite_rule('music/([^/?]*)/?$', 'music/?artist=$1');
}
add_action('init', 'custom_rewrite');
Upon saving permalink settings (using "day and name"), this created the following .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^music/([^/?]*)/?$ /music/?artist=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Upon navigating to /music/<artist name here>/, depending on different permalink settings, I will either get a 500 error or I will be shown the home page.
For method 2, this is the code I added to functions.php:
function custom_rewrite() {
add_rewrite_rule('music/([^/]*)/?$', 'artist/?artist=$1');
}
add_action('init', 'custom_rewrite');
Upon saving permalink settings (using "day and name"), this created the following .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^music/([^/]*)/?$ /artist/?artist=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Again, upon navigating to /music/<artist name here>/, depending on different permalink settings, I will either get a 500 error or I will be shown the home page.
Is there something I'm missing in the .htaccess file? Am I somehow conflicting with Wordpress' permalink settings? Is this simply just not possible in Wordpress? Any help would be greatly appreciated.
Related
I am developing a theme for WordPress by following some tutorials. The main page works well, loading post of a custom post type, and the page to see the contents of the cpt also following the Wordpress nomenclature: single-{name-cpt}.php.
The problem is when I create a normal page. When entering the URL of the page, the error page appears 404.php.
I have refreshed the link structure and verified that the .htaccess is correct.
What could be happening so that it does not load page.php?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Custom links structure: /blog/%postname%/
SOLUTION: I put this line in .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
-->RewriteRule ^event/([^/d]+)/([^_]*)/?$ index.php?pagename=event&eventid=$1 [QSA]<--
RewriteBase /teatro/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /teatro/index.php [L]
</IfModule>
The final url is : www.events.com/teatro/event/2/ExampleEVENT(this is not relevant)/
this is my first question and sorry for my English.
Before start my question I have seen some similar questions about this and I found "the solution" but in my case doesn´t work.
I found this link: https://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule
Ok. My question started because I have a plugin in Wordpress (EventBooking) and when I create a new event in the BackEnd the url for default in the FrontEnd is this:
www.events.com/teatro/event/?eventid=2
And I want a friendly url like this :
www.events.com/teatro/event/[name of event] (whitout id).
in the .htaccess I have this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /teatro/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /teatro/index.php [L]
</IfModule>
In the database the name of field of a Event is id not eventid but the original url that works in the frontEnd , is www.mydomain.com/teatro/event/?eventid=2
I think the problem is here. But I don´t know.
I tried add new Rewriterule in functions.php of my theme but doesn´t work.
Thanks
First of all change your permalink structure to /%postname%/ and then install this plugin "CUSTOM POST TYPE PERMALINKS", once you have done that, you'll be able to see a new taxonomy under your wordpress permalinks's page through which you'll be able to customize your custom post type permalink's structure, change it to /%postname%/%postname%/ to make it what you're looking to. If the existing existing taxonomy is %event-plugin% then do it accordingly.
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/
In a custom CMS I build I'm using the following for my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
When a user hits www.mysite.com a script determines the page to load based on a slug of the page in the database. This is working fine, however I want to take it one step further. Right now I can do www.mysite.com/products and it will serve me the data for the products page. What I want to do is add product filtering to the URL. For example:
www.mysite.com/products/collection/summer-collection
or
www.mysite.com/products/mens-navy-blue-blazer-19285
or
www.mysite.com/products/category/outer-wear
I do have the Product Creation module generating a unique product slug already, so I just need to be able to modify my .htaccess to get this working.
I have a wordpress website and within the root directory a folder called /ideal/.
The function for the /ideal/ folder is to make payments trough the website from visitors.
Everything worked well for a while, since a few days there is a problem with the page.
When i navigate to my website http://www.nibincasso.nl/ideal/ it wil show up with a 404 error.
With the release of wordpress 4.0 it looks like wordpress is trying to make some sort of dynamic link for the folder /ideal/.
However i want it to open as a static page, not by making it a wordpress dynamic page. “http://www.nibincasso.nl/ideal/index.php”.
Example of .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
Can someone help me with a solution for this problem?
Kind regards,
Fabi
Update *
I created a new subdirectory on my root with a blank index.php page only saying test
This one opens fine. But when i try to enter the subdirectory /ideal/ with the index.php i get a 404 error. How come?
Try following
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ideal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ideal/index.php [L]
</IfModule>
# END WordPress
There seems to be a problem with the php code inside the index from the /ideal/ folder.
I will search for the solution this is not a wordpress problem.
Thanks for helping me for so far.