Regex in add_rewrite_rule for wordpress for year and episode name - regex

I think this is my last problem to solve before everything clicks into place:
I have a homepage with a custom plugin that sends some data to another page, I am building a theme for this website that works with the plugin.
So in the theme functions.php I have added a
function myvar($vars){
$vars[] = 'ep_year';
$vars[] = 'ep_name';
return $vars;
}
add_filter('query_vars','myvar');
works a charm, I can send those values over to a custom page with a custom template assigned.
This has a permalink as follows:
http://ngofwp.local/episode/
and when I send the data over it looks like so:
http://ngofwp.local/episode/?ep_year=2011&ep_name=silly_donkey
I know I have to use an add_rewrite_rule so I've started coding that as follows:
function custom_rewrite_rule()
{
add_rewrite_rule('^episode/([^/]*)/([^/]*)/([^/]*)?','ep_year=$matches[1]&ep_name=$matches[2]','top');
}
add_action('init', 'custom_rewrite_rule');
(this is pasted from an example I found)
But now for the life of me I have no clue about the formulae to get it to work. I have read the regex rules but not sure
What I'd like it to look like is this:
http://ngofwp.local/episode/2011/silly_donkey
The
http://ngofwp.local/episode/
is given by wordpress's permalink setting
Would anyone regex savvy be able to help me out please?
We are a podcast that talks about new games on old platforms and I am migrating the site from node.
Thank you very much in advance

Related

Simple Laravel route not working

I am currently in the middle of doing a Laravel tutorial on Youtube and I've been catching on pretty quickly but I hit a snag and I have absolutely no idea what the problem is. I'm trying to route to a view and I am receiving an error saying that the page does not exist. Here is what I got (forgive me if my terminology is lacking):
The web.php file in the routes folder is configured for 'companies' to go to the 'CompaniesController':
Route::resource('companies', 'CompaniesController');
The create function located in the CompaniesController only purpose is to return the view 'companies.create' located in the appropriate place, 'resources/views/companies/create.blade.php'
public function create()
{
//
return view('companies.create');
}
If more information is needed let me know but this should be pretty straight forward. Other functions in the controller work fine, its only the one that is the most simple that isn't working.
Appreciate any help I get.
If your http request is GET:
Route::get('/companies', 'CompaniesController#create')
Else if request is POST:
Route::post('/companies', 'CompaniesController#create')
create would respond to a POST request by default, e.g., the endpoint of a creation form. It sounds like you're trying to display a simple view with a GET.
See https://laravel.com/docs/5.5/controllers#resource-controllers

Create subdomain for each user that signs up

I am developing a project in Coldfusion with CFWheels MVC Framework with URL Rewriting enabled. It involves user registration and each user should be presented as username.domain.com instead of www.domain.com/users/username. Moreover once I am on username.domain.com all child pages should work as:
username.domain.com/page1
username.domain.com/page2
username.domain.com/search?k=xyz
... etc
which I am unable to achieve.
I have updated my DNS settings of the particular domain so that *.domain.com all point to the same host. What am I still doing? I found this configuration , but I have not figured out how to implement it.
Sorry this is more of an extended comment than an answer
The code has a name of coldfusion-subdomains.cfm but it looks like something that would go into application.cfc. If you look at https://github.com/cfmaniac/CF-SubDomains , it states
CF-Subdomains is a snippet of code (best used in your OnRequest Method of Application.cfc) to detect and include files from a subdirectory on your server and let it act like a subdomain.
So from here, I would go to the cfwheels documentation so see if it does anything special with OnRequest()
I don't see anything that wraps around OnRequest(), so maybe it can be used as is
You may also want to consider url re-writing instead
http://docs.cfwheels.org/docs/url-rewriting

How can I write a regex to match everything but a char?

I've switched in my wordpress blog from urls like this:
/blog/2012/01/01/how-to-build-a-website
To shorter urls like this
/blog/?p=123
Wordpress has a search engine who works like this
/blog/search/?s=how to build a website
And search for the s params.
I'm trying to use .htaccess Redirectmatch to redirect all the old urls to the search url with the title of the post as the s params.
So if the user serf to
/blog/2012/01/01/how-to-build-a-website
should be redirect to
/blog/search/?s=how to build a website
I've coded this
Redirectmatch blog/\d+/\d+/\d+/(.+) http://www.mysite.com/blog/?s=$1
But this regex grap the whole string after the last / within the - symbol inside it.
In this way if a user serf to
/blog/2012/01/01/how-to-build-a-website
Will be redirected to
/blog/search/?s=how-to-build-a-website
while I want the user redireced to
/blog/search/?s=how to build a website
How can I write the regex to do this?
EDIT:
Yes guys, I know that this kind of urls are ugly :) But I just would know how to do it, because behind this there are some technical issues I'm trying to solve..
Please don't do this. I know it can seem tempting to go for short URLs; after all, you get things like TinyURL and such. Isn't it better to have /blog/?p=123 than /blog/2012/01/01/how-to-build-a-website?
No. It's not.
The reason is because when someone posts a link to your blog article, the longer URL means something. It tells the person how old the article is. It gives the title. It helps people find your article; after all, the URL is given a lot of weight by Google when indexing your site.
URLs used to be built for computers. Something like /blog/?p=123 is perfect for computers; it's easy to parse, it doesn't require any extra database lookups. You can write two articles named "How to Build a Website" and the blog engine doesn't have to make sure it adds a -2 on the second one. It maps easily to the actual structure of files on the server, without making up structure in the URL.
But we've realized since that URLs can be built for humans, too. The URL /blog/2012/01/01/how-to-build-a-website has a form that can be easily understood by humans. Sure, it's a bit longer to type, but all the bits you're typing are easier, and most URLs are copy'n'pasted anyway or just clicked on. It's more work for the computer, sure, but it's worth it. It makes the Internet friendlier.
So I'm sorry, but I won't help you. :)

Regular expression for URL filter that makes it hard to read the filterd URL

I want to insert a URL filter and I would like the URL to be hard to dechiffre.
For example .*porn\.* in a way maybe that it uses the ASCII code for the letters in hex form .
Of course, the example is obvious and I definately will leave that one as it is ;)
But for the others I would like them to be hard to read!
Thx!
You can use the $_GET function in PHP to pull an ID out of the URL and display it that way, similar to Youtube with their "watch?v=". I recently did one using "?id=49" (I only have a few pages ATM, I will have about 70 soon). What I did is use a database with a song_id to index the information. I use the same basic layout, but you can use the ID to access information wrapped in PHP so that it doesnt get sent to the browser but will still display the page you want.
Or if you really want it to look crazy, you could use a database using the SHA() or MD5() function to encrypt it.
and your display will look like /page.php?id=21a57f2fe765e1ae4a8bf15d73fc1bf2a533f547f2343d12a499d9c0592044d4.

Django url pattern to retrieve query string parameters

I was about ready to start giving a jqgrid in a django app greater functionality (pagination, searching, etc). In order to do this it looks as though jqgrid sends its parameters in the GET to the server. I plan to write an urlpattern to pull out the necessary stuff (page number, records per page, search term, etc) so I can pass it along to my view to return the correct rows to the grid. Has anyone out there already created this urlpattern I am in search of?
Thanks much.
The answer to this was simpler than I realized. As stated in Chapter 7 of the djangobook in the section titled "Query string parameters" one can simply do something as follows, where "someParam" is the parameter in the query string you want to retrieve. However, Django is designed to be clean in that address bar at the top of the page so you should only use this option if you must.
The query string might look something like this.
http://somedomainname.com/?someString=1
The view might look like this.
def someView(request):
if 'someParam' in request.GET and request.GET['someParam']:
someParam = request.GET['someParam']
Hopefully this is of some help to someone else down the road.