w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Javascript: match slug of a URL
Try this: var slug = url.match(/.*/([-a-z0-9]+/i)[1]; .*/ skips over everything until the last /. [-a-z0-9]+ matches 1 or more alphanumerics or hyphens. Putting the latter in (...) makes it a capture group, and [1] returns the first capture group.

Categories : Javascript

How to do a 301 redirect in htaccess while keeping the slug of the original page
When migrating a blog, you need to use a 301 redirect. 301 redirects, by definition, will change the path in the url bar. From memory, you'll need to do all of these steps if you need to make it lowercase too. In your VirtualHost, add RewriteMap lc int:tolower In your .htaccess, add: RewriteCond %{REQUEST_URI} [A-Z] RewriteRule (.*) ${lc:$1} [R=301,L] RewriteRule /blog/bid/([0-9]+)/(.*) /$2 [R=301,l]

Categories : Regex

Redirect url does not match registered redirect url in instragram
It is clearly stated in the Instagram iOS SDK documentation that the URL Scheme needs to be structured as: ig[clientId]:// So in your case: ig3213f9b... Will not work, try ig32313...://

Categories : Iphone

Redirect URL by query string match?
You can do this with mod_rewrite like this: RewriteCond %{QUERY_STRING} ^/knowledgebase/$ RewriteRule ^index.php$ /knowledgebase/ [L,R=301] Edit: When debuging htaccess rewrite rules I find this tool very useful

Categories : Htaccess

htaccess redirect exact match, exclude all query strings
I would suggest you to use mod_rewrite instead of mod_alias in your htaccess : RewriteEngine On RewriteBase / RewriteRule ^search/?$ / [L,R=301]

Categories : Htaccess

Excel 2007 VBA MATCH function is not finding a match, but a match does exist in that range?
You must use MatchType of 0 to use wild card characters (* or ?) see: http://office.microsoft.com/en-001/excel-help/match-function-HP010062414.aspx Use Application.Match("More items related to*", Range("AZ1:AZ1000"), 0)

Categories : Excel

Ember js using name for URL slug
What you can do is to hook into the serialize hook of your CategoryRoute and provide there the slug. Example: App.CategoryRoute = Ember.Route.extend({ setupController: function(controller, category) { controller.set('model', category); }, serialize: function(model) { return { category_slug: model.get("name").toLowerCase() }; } }); This way you can remove also the slug computed property in your model, and in your links you then do: {{#each model}} {{#linkTo 'category' this}}{{name}}{{/linkTo}} {{/each}} Hope it helps.

Categories : Ember Js

preg_split url slug and id
Try this: preg_split('/-(?=d+$)/', $slug); I use - as separator and I check if it is followed by a number at the end of the string with a lookahead (?=...)

Categories : PHP

Turn a slug into an id
In your routing file: your_route_name: pattern: /my_app/{category}/{subcategory}/{page} defaults: { _controller: YourBundle:YourController:FindPost } In your controller: public function FindPostAction($category, $subcategory, $page) { //...use $category, $subcategory, $page here }

Categories : PHP

Issue with URL slug.
You need QSA (Query String Append) flag to preserve existing queries while redirecting. You don't need 2 rules just for handling a trailing slash. Replace your code with this: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^([a-z0-9_-]+)/?$ /index.php?id=$1 [L,QSA,NC]

Categories : PHP

get unique slug in codeigniter
easy to use and really helpful to create unique slugs have look on CI slug library read its documentation to implement it.

Categories : PHP

Laravel Slugs with Str::slug
OK, I did it this way: // I have a slug field in my courses table and a slug field in my categories table, along with a category_id field in my courses table. // Route Route::get('courses/{categorySlug}/{slug?}', function($categorySlug, $slug) { $course = Course::leftJoin('categories', 'categories.id', 'courses.category_id') ->where('categories.slug', $categorySlug) ->where('courses.slug', $slug) ->firstOrFail(); return View::make('courses.show')->with('course', $course); }); Works like a charm. It gets the $categorySlug and $slug variables then uses them to filter the Eloquent model Course to get the correct course object from the database. EDIT: You can generate a URL in your view like: http://www.example.com/courses/it-training/mcse

Categories : String

single.php for taxonomy slug
I'm not sure if I have misunderstood your question, but WordPress provides a template hierarchy so you can create templates for specific pages. Just create a taxonomy-myslug.php in your theme file and WordPress will pick it out automatically. If there is commonality between different templates, use get_template_part() to ensure you only code once.

Categories : PHP

Is there a Lemoon route for /{slug}
Lemoon adds the catch-all route {slug*} to the end of the route-table, effectively catching everything that is not handled by other route handlers such as custom Controllers etc. In order for Lemoon to respond to the request http://www.mylemoonsite.com/blogpost3 you need to have a page in your site with the permalink blogpost3. Since you get a response when requesting http://www.mylemoonsite.com/blog/blogpost3 I am guessing the permalink for your page is blog/blogpost3. There are 2 things you can do to get a response from the path http://www.mylemoonsite.com/blogpost3. Edit the permalink of the page Add an alias to the page If you add the alias blogpost3 the page will respond to both http://www.mylemoonsite.com/blogpost3 and http://www.mylemoonsite.com/blog/blogpost3. When adding t

Categories : Misc

htaccess rewrite slug to seo url
Use: RewriteEngine On RewriteRule ^works/(.*)$ works/show.php?slug=$1 [L] You can also put your .htaccess file into works folder with this code: RewriteEngine On RewriteRule ^(.*)$ show.php?slug=$1 [L]

Categories : PHP

htaccess slug 404 error
You fix this in your CMS, so that you either redirect to the correct slug or create pages for "result" and "about". Otherwise you can do this right in your htaccess file: Add this right below RewriteEngine On: RewriteRule ^about$ /about-us [L,R=301] RewriteRule ^result$ /my-result [L,R=301]

Categories : PHP

Rails 4 Friendly Id Slug Not Updating
In FriendlyId 4 (Rails 3 compatible) there was a method should_generate_new_friendly_id? and you could define it on your model to control when slug is regenerated. Try def should_generate_new_friendly_id? name_changed? end to regenerate slug when name changes. EDIT FriendlyId version 5 (Rails 4 compatible) doesn't regenerate slugs on save anymore. To restore this functionality you can either set slug column to nil before saving or use the solution provided above.

Categories : Ruby On Rails

MySQL slug function on insert
Are you looking for something like this? CREATE TABLE people (`name` varchar(128), `slug` varchar(128)); -- It's not a real function it's just an oversimplified example -- you need to implement your own logic CREATE FUNCTION NAME_SLUG(name VARCHAR(128)) RETURNS VARCHAR(128) RETURN LOWER(REPLACE(name, ' ', '-')); CREATE TRIGGER tg_people_insert BEFORE INSERT ON people FOR EACH ROW SET NEW.slug = NAME_SLUG(NEW.name); INSERT INTO people (`name`) VALUES ('Jhon Doe'),('Ian Martin Louis'), ('Mark Lee'); SELECT * FROM people; Output: | NAME | SLUG | --------------------------------------- | Jhon Doe | jhon-doe | | Ian Martin Louis | ian-martin-louis | | Mark Lee | mark-lee | Here is SQLFiddle demo

Categories : Mysql

In WordPress, how do I add a folder name in front of a slug?
That sounds like a bug in the theme. My first guess is that there's a naming collision. I believe "category" is the slug Wordpress uses for displaying post categories, while the theme is trying to use "category" to rewrite page permalinks. As an experiment, try editing Wordpress' built-in Category base option. Try going to Dashboard > Settings > Permalinks, and at the bottom under "Category base" set the field to something besides "category", like "mycats" or whatever. For fun try setting it to "category" explicitly and see what happens.

Categories : PHP

Django Slug Not Working In get_absolute_url
Based on what @Peter DeGlopper stated in comments: It looks like your trying to get the absolute URL using a Class Based View. Don't use reverse here, instead you should always give your URLs a name, and then refer to that. For example this is how it should look: model @models.permalink def get_absolute_url(self): return 'blog_entry', (), {'slug': self.slug} urls url(r'^entry/(?P<slug>[^.]+).html', blog_views.EntryDetail.as_view(), name='blog_entry'),

Categories : Django

Hierarchy tree to get parent slug
OK, here's a script to sink your teeth into as been as i had a few minutes. Look at the comments! it explains everything in the script. It to be honest, should work straight away as i've copied your array structure, but please read it and understand it, don't just copy and paste blindly, you wont learn anything that way (i wouldn't normally provide full working code, but this ones pretty hard to explain). <?php /** * Heres your categories array structure, they can be in any order as we will sort them into an hierarchical structure in a moment */ $categories = array(); $categories[] = array('id'=>5, 'parent_id' => 4, 'name' => 'Bedroom wear', 'slug' => 'bwear', 'status' => 1); $categories[] = array('id'=>6, 'parent_id' => 3, 'name' => 'Rolex', 'slug' => 'rol

Categories : PHP

Wordpress loop how to get tag slug and be value in query_posts
You have to pass the tag id in the query_posts and the wp_get_post_tags() returns the array not the id so the best to achieve the posts by tag you have to pass the tag-id which <?php $t = wp_get_post_tags($post->ID); query_posts( 'cat=45&tag=' . $t[0]->term_id. '' ); // The Loop while ( have_posts() ) : the_post(); ?> there can be multiple tags so you have to loop through $t to get all the tag ids Please refer to this manual wp_get_post_tags

Categories : Wordpress

Trouble using "Slug" in Django DetailView
because Django's generic DetailView will look for "slug" or "pk" to fetch its object It will, but you haven't told it what model it is to use. The error is very clear about this: Define TagDetailView.model, TagDetailView.queryset, or override TagDetailView.get_queryset(). You can use the model or queryset attributes to do this, or the get_queryset() method: class TagDetailView(...): # The model that this view will display data for.Specifying model = Foo # is effectively the same as specifying queryset = Foo.objects.all(). model = Tag # A QuerySet that represents the objects. If provided, # the value of queryset supersedes the value provided for model. queryset = Tag.objects.all() # Returns the queryset that will be used to retrieve the object tha

Categories : Django

rails paperclip has_attached_file path with :slug?
You must use paperclip interpolations. This works for me with paperclip 3.5.2 class User < ActiveRecord::Base extend FriendlyId friendly_id :name, use: [ :slugged, :finders ] Paperclip.interpolates :slug do |attachment, style| attachment.instance.slug end has_attached_file :picture, styles: { large: "512x512!", medium: "256x256!", thumb: "128x128!" }, default_url: "/images/:class/:style/missing.png", hash_secret: "xxxxxxxxxxxxxxxxxxxxxx", url: "/system/:class/:attachment/:slug/:style/:hash.:extension", path: ":rails_root/public/system/:class/:attachment/:slug/:style/:hash.:extension" end It also demonstrates the use of hashed file names to hide private information in the file name. Url and path must match unless you set up some routing in the web s

Categories : Ruby On Rails

Can I use .htaccess to convert a url slug to a POST request?
NO it's not possible - mod_rewrite rules cannot alter or rewrite POST data. Obviously there are some security constraints in doing so, hence mod_rewrite developers didn't allow that.

Categories : Apache

Specifying slug in reverse order in Rails routes
Is this not working? get '/:tenant_slug/hats', to: 'store/hats#index', as: 'hats' Should generate the following route, and params[:tenant_slug] will contain that part of the URI: hats GET /:tenant_slug/hats(.:format) store/hats#index

Categories : Ruby On Rails

Wordpress query not filtering by taxonomy when specifying a slug
You may try this $args = array( 'post_type' => 'news', 'name' => '$slug, 'posts_per_page' => 1, 'tax_query' => array( array( 'taxonomy' => 'news_type', 'field' => 'slug', 'terms' => 'press-releases' ) ) );

Categories : Wordpress

Cannot rename the slug for a custom post type
you are using a wrong array use this instead register_post_type( 'roofers-peakdistrict', array( 'labels' => array( 'name' => __( 'Peak District' ), 'singular_name' => __( 'Roofers Peak District' ), 'add_new' => 'Add New Peak District Page', 'add_new_item' => 'Add New Peak District Page', 'edit' => 'Edit Peak District Page', 'edit_item' => 'Edit Peak District Page', 'new_item' => 'New Peak District Page', 'view' => 'View Peak District Page', 'view_item' => 'View Peak District Page', 'search_items' => 'Search Peak District Pages', 'not_found' => 'No Peak District Pages found', ), 'has_archi

Categories : PHP

In cake php need to maintain the slug if the user delete its characters
Check the url and redirect if necessary All you need to do is check that the slug in the url is the current slug, and if not, 301 redirect to the right url: function view($id, $slug = null) { $record = $this->Foo->findById($id); if ($record['Foo']['slug'] !== $slug) { return $this->redirect( array( $id, $record['Foo']['slug'] ), 301 ); } ... } That way, if the slug is accidentally wrong, or if the slug changes (original record updated) the url is maintained correct and there is an enforced canonical url for each record.

Categories : Cakephp

Implementing a slug / clean URL system - general plan
Each product has a unique url associated with it in the database. When you perform a search you just return the correct unique url. That way you only ever work out what the url should be once, when the product is first added and that url will always relate to that one product. This is the stage you use your system to create that url

Categories : PHP

How to find slug name from url and make a dynamic query statement
Just swapping the order of the joins around a touch:- SELECT t1.name AS level_one, t2.name AS level_two, t3.name AS level_three, t1.id AS requested_id FROM categories AS t1 LEFT JOIN categories AS t2 ON t2.id = t1.parent_id LEFT JOIN categories AS t3 ON t3.id = t2.parent_id WHERE t1.slug = 'sports'

Categories : PHP

Problems with Slug size on Heroku when using Asset Sync Gem
You can add behavior that deletes the directory after assets:clean is run require 'fileutils' Rake::Task["assets:clean"].enhance do FileUtils.remove_dir "#{Rails.root}/public/assets", true end You can put that in your Rakefile.

Categories : Ruby On Rails

Form validation returns non-unique slug error after edit()
its because you've saved the slug in your DB and upon editing it. it returns an error because its referring to itself. you can try to make a call_back function upon updating your new value, that function then connects to the model and runs a query checking the new value. You can try something like this: UPDATE you should never update the ID especially if its a primary key - auto increment you can just use it to find the specific slug that is to be updated, you can check the slug uniqueness but not the id if its the primary key public function check_slug() { $id = $this->input->post('id'); $data = array('id' => $id); if($this->model->check_slug($data)) return false; else return true; // end if } // end function public function upda

Categories : PHP

Django DetailView failing to find object based on SLUG
Django's slugify method: Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace. you are looking for a Camel Case'd tag: http://localhost:9999/tag/RandomTag/ you need to use lowercase: http://localhost:9999/tag/randomtag/ # or `random-tag` depending on the name Check your DB to see exactly how the slug is saved

Categories : Django

Django: "How to get the slug from url() before passing it to MyClass.as_view()?" or "How to check if registration is open?"
If I understand correctly, your view is a DetailView of the event, correct? In that case, use something along the lines of: class EventDetailView(DetailView): model = Event def dispatch(self, request, *args, **kwargs): if self.request.user not in self.object.registered_users.all(): return HttpResponseForbidden() else: return super(EventDetailView, self).dispatch(request, *args, **kwargs) This assumes that you have a M2M key between User and Event models, called registered_users on the Event side; change the code to fit your situation.

Categories : Django

Grab Rails 4 asset pipeline URL in Rake task on Heroku slug compilation
Ultimately, this is the solution I had to go with: desc 'Capture asset pipeline stylesheet and javascript URLS to Redis' task 'assets:urls:capture' => :environment do # unfortunately, this way doesn't work when deploying #controller = MyApp::Application::ApplicationController.new #desktop_url = controller.view_context.stylesheet_url('desktop') #mobile_url = controller.view_context.stylesheet_url('mobile') desktop_url = MyApp::Application.config.action_controller.asset_host desktop_url += "/" + AssetSync.storage.get_remote_files.select{|d| d.include?('desktop') && d.include?('.css') }.first REDIS.set('desktop_css_url', desktop_url) puts "Saved desktop url to Redis for Store Rails app: #{desktop_url}" mobile_url = M

Categories : Ruby On Rails

Incrementing the slug by avoiding Integrity error in django models save method
You will have to use loop instead of just a one condition. Try this: class Publisher(models.Model): name = models.CharField(max_length=200) slug = models.SlugField(max_length=150, unique=True) def save(self, *args, **kwargs): if not self.id and not self.slug: slug = slugify(self.name) slug_exists = True counter = 1 self.slug = slug while slug_exists: try: slug_exits = Publisher.objects.get(slug=slug) if slug_exits: slug = self.slug + '_' + str(counter) counter += 1 except Publisher.DoesNotExist: self.slug = slug break super(Publisher, self)

Categories : Django

Why is a "redirect" (that is, `return "redirect:/myPage"`) not working for my Tiles page definition?
Thanks to hints left by Sotirios' comments, I discovered that my inability to "redirect" to "myPage" had nothing whatever to do with Tiles. Rather, after a harder look, I realized that it was the configuration of the controller associated with "myPage". I had to add the following "public ModelAndView myPage(HttpSession session)" method to the Controller (see snippet, below), in order to perform a successful redirect (i.e., from another controller)...i.e., using return new ModelAndView("redirect:/myPage"); The problem was that the "myPage" controller did not contain an "public ModelAndView myPage(HttpSession session)" method...(thanks again, Sotirius). Below, is the "public ModelAndView myPage(HttpSession session)" method - code snippet) @Controller @Scope("session") @

Categories : Java

Redirect an URL by default, and show the original page when ?redirect=false is shown
Well... you actually need to test for that query parameter. something like: if ((Request.QueryString["redirect"] == null) || (Request.QueryString["redirect"] != 'false')) Response.Redirect("NEW URL"); } base.OnLoad(e); The test for null is there in case the redirect parameter wasn't passed in.

Categories : Asp Net

Excel VBA: Can't get a match, error "Unable to get the Match property of the WorksheetFunction class"
Use the Application.Match function which allows for better ability to trap errors. When using the WorksheetFunction.Match, when a match is not found, it returns an error, which is what you're experiencing. If Not IsError(Application.Match(Cells(e, 1).Value, myrange, 0)) Then 'Do stuff when the match is found Cells(e, 3).Value = "Yes" Else: Cells(e, 3).Value = "No" End If You could also potentially use the CountIf function: If Application.WorksheetFunction.CountIf(myRange, Cells(e,1).Value) > 0 Then Cells(e,3).Value = "Yes" Else: Cells(e,3).Value = "No" End If Neither of these approaches requires you to use the m1 variable, you can assign this variable within the True part of the If/Then statement, if you need to identify where the match is found.

Categories : Excel



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.