How to change url_alias partially according to a pattern Drupal - drupal

How to change url_alias partially according to a pattern?
We have site with reports to users.
We continue to update the reports with new content node but the url_alias kept same.
For example,
/report/report_a
/report/report_a/subreport_1
/report/report_b
…...
Users bookmark the pages. So they can get into the reports directly.
Recently we change the path pattern with /docs/ in front:
/docs/report/report_a
/docs/report/report_a/subreport_1
/docs/report/report_b
…...
Now the new content nodes go to these url_alias.
But the users have booked mark the pages.
So we want to make them previous book marks, url_alias, can be redirected into the new path.
For example,
/report/report_a to be redirected into /docs/report/report_a
/report/report_a/subreport_1 to be redirected into
/docs/report/report_a/subreport_1
That means to make /report/* paths to be redirectly to /docs/report/* paths
Here * is wildcard.

Do the old report pages still exist? You could add a bit of javascript to each page that redirects to the new location...

Can you create aliases for the old nodes? If there are a lot, it probably wouldn't be too hard to run a script that takes all the old paths and creates aliases for them.
In D7, URL Aliases are under Config | Search and metadata

It's probably easiest add a redirect to your .htaccess file. Something like this should work for your example:
Redirect /report/ /docs/report/

Related

Creating static paths with multiple constrained params

I'm now in the process of developing my small project and I'm not sure if it's even possible to do this the way I will describe below, so... I have dynamic routes like "/[community]/[townName]". How can I generate static paths where [townName] is constrained to [community]?
In other words - let's say we have townName "abc1". This town is in community "xyz1" so the page /xyz1/abc1 should be accessible and NOT throw 404. But there is also town with the same name "abc1" in "xyz2". So the path /xyz2/abc1/ should also be accesible.
However there is no town with same name in community xyz3 so I do not want to generate page for /xyz3/abc1/ - user should see 404 error.
Of course each town has it's unique ID in database and I could use it to generate pages, but I want my url to be SEO friendly.
All help and tips are appreciated. Thanks!
You should check getStaticPaths and dynamic routes from official Next.js website. It has more than one way to do what you want but there are additional customization options.

Change URL in new Firebase (from May 2016)

Earlier when using Firebase, there was an option to use our own url like myapp.firebaseapp.com (including firebaseapp.com part). But from May 2016, when I create a project, it gets an auto-generated URL like my-app-1c75b.firebaseio.com, and I cannot find place to edit that (because 1c75b part in URL is not nice). I want to know is there any way to edit that like before?
Note - I don't want to use a paid domain like www.example.com. I just want to customize my Firebase URL as myapp.firebaseapp.com
When you create a project in the new Firebase console, it will indeed add a "random" code to the project name. There is currently no way to prevent this code in the new console.
When you upgrade an existing project from firebase.com into the new console, the app name will remain unchanged. So if you already have myapp.firebaseapp.com on a firebase.com project, you will keep that URL after importing/upgrading.
When creating a new project, you get an screen where you can enter the name.
In the textfield for project-id ou can enter a project-id.
your project-id needs to include a dash
when it doesn't, it will say something like, it is already used or it places the dash itself, with some custom characters.
The project-id itself is fixed, so you should create a new project and copy everything.
When you create your project the url is based on the project name you give. If your project name is "Foo Bar", your url will be https://foo-bar.firebaseapp.com (assuming it isn't already taken).
Last week Create Project window was showing possible firebase.com subdomain that will be assigned while you were typing project name. It's first come - first served basis so if you type a name already taken it automatically adds some character-number combination at the end.
Today same window doesn't show that while typing, you can only see it after you create your project and go to settings dashboard, there is no way to change given subdomain on the same dashboard.
Update 10.07.2017
I'm getting random hex number added from time to time, I can't always get plain name even if name is supposedly original one.
If you choose a name unique enough within Firebase, they will give you a domain for your app as in https://myapp.firebaseio.com.
I tried several times, sometimes it gives something like https://project-(long-random-number-sequence).firebaseio.com and other times something like what you've encountered. My personal experience shows if you give your app a name suffixed with "app" then you have a higher chance of being unique and getting the "nice" URL.
Scroll down in 'Manage Site' and create a new site, then deploy there.
You can't change your domain, but you can change the host! You can make as many sites as you want.

How many controller files should I create in my Symfony2 application?

In the src/AppBundle/Controller folder, there is a file called DefaultController.php.
I'll create url's like below, should I use just DefaultController.php for all URL requests or is it recommended to use a different controller.php file (UserController.php, FeedController.php, etc) for each part of the site? (profile, feed, settings, etc)
I also have another question. As far as I understand, we put our html files in our /App/Resources/views folder to keep them separated. Do I need to create a specific file for each part of the website just like flat PHP? (settings/index.php, settings/password.php, settings/things.php, settings/security.php, etc).
I am not sure whether this question is suitable for SO or not.
settings
/settings
/settings/password
/settings/things
/settings/security
/settings/privacy
/settings/ban
/settings/notifications
/settings/mail
/settings/mobile
/settings/applications
/settings/advertising
/settings/invite
user
/username
/username/photos
/username/friends
/username/posts
feed
/feed
/feed/posts/postid
For both questions is no hard answer. I should create a controller for each part of your website AT LEAST. Theoretical you could throw everything into one controller but it will be a very long list if you are finished. Another problem is that your action names like indexAction will repeat which is of course not possible because every method must have a different name. And names like index1Action, index2Action and so on is also not a proper solution :-). Another helper is to create an own controller for every ENTITY.
Twig files should only be written for one page only or only for a part of a page. Imagine that you have a homepage with last 10 newsitems but also a news page with more news items (maybe with pagination). The newsitems themselves looks the same on both pages. In this case you could make a home.html.twig, a news.html.twig and also a newsitem.html.twig. Both home and news will include newsitem to show the newsitems...
Hope i gave you a light.

Drupal pathauto usage

I have a node called artists. It has a field called shortname. I want to have it so that when I add an artists with shortname = 'foo' you can navigate to http://bar.com/foo/ and it will show that artist's node.
What's the magic configuration in pathauto to make this happen?
You need The path auto which requires the token module. You'll need to set up your path using the [title-raw] token. Which should be used with care as node titles could inject bad stuff into your URLs.
It's not a good idea to have http://example.com/[title-raw]. You'll end up with possible name collisions. Try http://example.com/artist/[title-raw]

Drupal Views (Page) Using Human-Friendly Path

I have CCK and Views module installed. For the sake of this question scope, I'll call the content type as Project. Projects have many Members.
Project nodes are accessible through /project/project-name. I want to be able to display list of members through path /project/project-name/members.
Is there any way to do this?
Currently I have a views setup for page display on path /project/%/members, and have the argument taken from the url. I realize I can't use "Node ID from URL" option directly since it's node name instead of node id. Therefore I tried to enable "PHP Code" argument. But the problem is, Drupal Views always assume that the parameter is "project-name" and therefore ignored my php code argument setting. Anyone knows how I might be able to do this?
Thanks
Yes, you can actually use the "Node ID from URL" option, and you should.
Use the path or pathauto module to generate human-readable URLs for your projects in the form project/project-name. This will create a human-readable alias for the node, but the underlying Drupal system path is still node/nid.
Views can still use the "Node ID from URL" as an argument (or Contextual filter, as they are known in Drupal 7) even with human-readable aliases for those ugly paths.
If the project's name is the node title you can get what you want pretty easily.
You can pass the node title as argument instead of the nid, but the result will be the same. You get some options to use lowercase, transform - to space ect, as what you can do in a url is limited compared to a node title.
The rest of the view would be the same, as the solution using node nids in the url.
You need to create path aliases for /project/project-NID/members to /project/project-Name/members
I asked this exact question a month ago. :)
drupal link to view dependent on argument

Resources