URLrewrite rule to replace hyphen with %20 - url-rewriting

I'm using tuckey.org rewrite urlrewrite filter and I would like to create rule for url with hypen.
like from /author/person-name to /topics/Author/Person Name
In above rule, hyphen must be replace with space %20 in url and Uppercase of Author and Person Name
Can someone help with writing rule for this?

Related

Laravel - getting ID from a URL and parsing URL having dash (-) into it

i have an ID in a url. its like this
http://mysite.test/category/subcategory/title-13
now in Laravel.
i want to parse this part of URL in my web.php route file so that i can detect and pass them in a function.
category/subcategory/title-13
and route must be like this.
Route::get('{category}/{subcategory_slug}/{slug}-{id}/', 'ItemsController#item')
i tried this but its not working. because of "-"
and here title has dashes (-) into it as well. like
http://mysite.test//jobs/articles/get-your-dream-job-16
Your slug placeholder consumes everything up to the next slash, including the -, so the rest never matches.
Laravel lets you add your own pattern against which to match a placeholder, using the where method.
If you set your slug's pattern to exclude the - character, it should work as you expect.
Route::get('{category}/{subcategory_slug}/{slug}-{id}/', 'ItemsController#item')
->where('slug', '[^-]+');
If your slug itself contains dashes, then you can use a lookahead to make sure there's always at least one dash left:
Route::get('{category}/{subcategory_slug}/{slug}-{id}/', 'ItemsController#item')
->where('slug', '.+(?=-)');

IIS7.5 URL Rewrite, with or without trailing slash

I'm using IIS7.5 and have a rule for rewriting a URL...
The rule is:
^trade/new_products/page([^/]+)/?.*$
But, this is only working when I don't include a slash - e.g.
http://www.website.com/trade/new_products/page1
I'd like it to also work with
http://www.toppstiles.co.uk/trade/new_products/page1/
Can I do this or do I need a separate rule?
This group ([^/]+) is catching everything but slash. If your page is only numeric you can try this one:
^trade/new_products/page([0-9]+)/?.*$
If not, you can use the non greedy modifier on the multiplier(+?):
^trade/new_products/page([^/]+?)/?.*$
Sorry - the rule was working as expected - it was another issue that was causing my problem!

Custom URI Scheme for application

I am creating a custom uri for my application. I wanted to know if there are any rules on the name of URI .. ie. can i use myApp_1.0 as an uri?
Ok got the answer, URI schemes can only contain letters, digits, plus ("+"), period ("."), or hyphen ("-"). also the URI is case insensitive, but it is recommended to use lower case only.
More details can be found at http://en.wikipedia.org/wiki/URI_scheme

url rewrite pattern generates to many redirects

I have been struggling with the same issue for a while now and I could not find an good answer yet. I'm using rack-rewrite to add some url rewrite rules to my app's middleware stack.
I have the following rule:
r301 %r{^/([^(docs|help|legal|login|account|apps)])(.+)/$}, '$1'
Which is not working properly or as I would expect it. I have tried one of my previous question's answer, but neither that works, it actually generates an event more weird behaviour (it redirects to an url without the domain name, just to the path).
What I am trying to do is:
if user requests http://example.com/ or http://example.com/random-path/ I need the rewrite rule to strip the slash, thus the examples would become http://example.com respectively http://example.com/random-path;
if the requested paths matches any of the paths in the list docs|help|legal|login|account|apps, do not strip the slash at the end of the path if exists, but add a slash if it's not there
I tried with two rules, one that ignores the listed paths above and strips slashes and one that adds the slash if it hits something from the list and the slash after the path is not there:
r301 %r{^/([^(docs|help|legal|login|account|apps)])(.+)/$}, '/$1'
r301 %r{^/([(docs|help|legal|login|account|apps)])(.+)/$}, '/$1/'
How could I write a rule that would do that, or two rules, because what I tried it did not work?
You can do that like so:
r301 %r{^/((?!docs|help|legal|login|account|apps).+)/$}, '/$1'
r301 %r{^/((?=docs|help|legal|login|account|apps).+[^/])$}, '/$1/'
example 1
example 2
and some documentation on lookahead and lookbehind
EDIT: stray parentheses.

Mod_rewrite rule doesent work

I need to rewrite some url on my site
http://wwww.example.com/poem.php?s=to-sally
to
http://wwww.example.com/poems/to-sally
I wrote this rule but doesnt work
RewriteRule ^poems/([a-zA-Z0-9-]+)$ poem.php?s=$1
A couple things:
Make sure you have RewirteEngine On, and actually have the mod_rewrite module loaded and running
I believe the paths being matched against start with /, but your rule dictates that the first character is p. Try replacing your match expression with ^/poems/([a-zA-Z0-9-]+)$ and see if that does the trick.

Resources